今天賣出的水果數量如下,請問老闆算今天賺了多少錢
let data = [
{ name: "蘋果", price: 30, amount: 5 },
{ name: "香蕉", price: 12, amount: 10 },
{ name: "櫻桃", price: 25, amount: 20 },
]
// 先算每種水果賺的錢,再加總
const res = R.pipe(
R.map(x => x.price * x.amount),
R.sum
)(data);
R.pipe 是由左往右
R.compose 是由右往左
// 12
R.pipe(
Math.abs,
R.add(2),
R.multiply(2)
)(-4)
// 6
R.compose(
Math.abs,
R.add(2),
R.multiply(2)
)(-4)