Last active
November 28, 2018 13:27
-
-
Save Yago/57e5b3a001a6b669020f844643588804 to your computer and use it in GitHub Desktop.
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
const calculator = { | |
sum(...args) { | |
return args.reduce((acc, n) => typeof n === 'number' ? acc + n : acc, 0); | |
}, | |
sumOldSchool: function () { | |
return [...arguments].reduce(function (acc, n) { | |
if (typeof n === 'number') return acc + n; | |
return acc; | |
}, 0); | |
}, | |
}; | |
calculator.sum(31, 7, 4); // return 42 | |
calculator.sumOldSchool(31, 7, 4); // return 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment