4 ms·
The extra args passed by map coupled with the optional extra args in standard methods is the cause of a lot of confusion, but this feels like a missed opportuni
by femto113 7y ago
The extra args passed by map coupled with the optional extra args in standard methods is the cause of a lot of confusion, but this feels like a missed opportunity for demonstrating functional programming. In the end author suggests
['1', '7', '11'].map(numStr => parseInt(numStr));
I think you'd learn something much more useful with
function radixParser(radix) { return numStr => parseInt(numStr, radix); }
['1', '7', '11'].map(radixParser());
> [ 1, 7, 11 ]
['1', '7', '11'].map(radixParser(8));
> [ 1, 7, 9 ]
['1', '7', '11'].map(radixParser(2));
> [ 1, NaN, 3 ]
- fastball 7y agoIf you're gonna use arrow functions, why not go all the way! const radixParser = (radix) => (numStr) => parseInt(numStr, radis);
- femto113 7y agobecause I still think function foo() { ... } is a clearer way of indicating "I'm defining a function named foo". I tend to use arrows only for anonymous methods.