Last active
March 7, 2016 19:03
-
-
Save ivancorrales/38a9e56409e055e9b8ae to your computer and use it in GitHub Desktop.
Re-factor the code in a functional-programming way
This file contains hidden or 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
| var shoppingCartTotalPrice = (function(){ | |
| var items = [ | |
| { | |
| name:'Domus IPA', | |
| amount:3, | |
| unitPrice:2.5, | |
| }, | |
| { | |
| name:'Cibeles', | |
| amount:6, | |
| unitPrice:2.0 | |
| }, | |
| { | |
| name:'La Victoria', | |
| amount:2, | |
| unitPrice:1.35 | |
| } | |
| ]; | |
| return ( | |
| function(){ | |
| var totalPrice = 0; | |
| for(var itemIndex=0;itemIndex<items.length;itemIndex++){ | |
| var item = items[itemIndex]; | |
| totalPrice+= (item.amount*item.unitPrice) | |
| } | |
| return totalPrice; | |
| }() | |
| ); | |
| })(); | |
| console.log(shoppingCartTotalPrice); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment