Created
April 5, 2018 09:21
-
-
Save indongyoo/c19cc721e2ec9cd54da3ce8828804701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 세 번째 인자에 `filter(selected)`를 전달하여 선택된 상품의 수량만 합산 | |
console.log( pdts.total(quantity, products, filter(selected)) ); // 7 | |
pdts.selected = { | |
// pdts.total의 before에 ...filter(selected) 추가 | |
quantity: _ => pdts.total(quantity, _, filter(selected)), | |
price: _ => pdts.total(pdt.totalPrice, _, filter(selected)), | |
// pipe로도 확장 가능 | |
discountedPrice: pipe(filter(selected), pdts.discountedPrice) | |
}; | |
// 선택된 모든 상품 수량 | |
console.log( pdts.selected.quantity(products) ); // 7 | |
// 선택된 모든 상품 기본 금액 x 수량 | |
console.log( pdts.selected.price(products) ); // 126000 | |
// 선택된 모든 상품 할인된 금액 x 수량 | |
console.log( pdts.selected.discountedPrice(products) ); // 110000 | |
// 선택된 모든 상품 중 할인 금액이 있는 상품의 총 수량 - before 이용 | |
pdts.selected.dq = _ => pdts.total( | |
quantity, | |
_, | |
filter(selected), // <-- ...before에 넘어감 | |
filter(discount)); // <-- ...before에 넘어감 | |
console.log( pdts.selected.dq(products) ); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment