Last active
December 1, 2018 06:40
-
-
Save yashwanth2804/72775ea33eff687d9e38a57a40f1488b to your computer and use it in GitHub Desktop.
Sample closure function with sum example
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
var BTCbank = function(BTC_balanace) { | |
return grandpa = (moneyspent) => { | |
// grandpa | |
BTC_balanace -= moneyspent; | |
return dad = (moneyspent) => { | |
// dad | |
BTC_balanace -= moneyspent; | |
return me = (moneyspent) => { | |
// me | |
return BTC_balanace -= moneyspent; | |
} | |
} | |
} | |
}; | |
// step-1 | |
// deposit 1000 to BTCbank | |
var bankBalance = BTCbank(1000); | |
// step-2 | |
// now grandpa spending amount is 300 | |
var afterGrandpaSpending = bankBalance(300); | |
// step-3 | |
// now grandpa spending amount is 200 | |
var afterDadSpending = afterGrandpaSpending(200); | |
// step-4 | |
// now grandpa spending amount is 499 | |
var aftermyDonaion = afterDadSpending(499); | |
console.log(aftermyDonaion); | |
/// simple way | |
/// console.dir(BTCbank(1000)(400)(100)(499)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment