5 ms·
It took me a little longer to understand higher order functions in JavaScript than it took me to understand for loops but once I “got it” then using something l
by dawhizkid 9y ago
It took me a little longer to understand higher order functions in JavaScript than it took me to understand for loops but once I “got it” then using something like array.filter((x)=> x%2===1) seemed cleaner and arguably “simpler” than the alternative but not “dumber.”
- mvindahl 9y agoAlso, unlike the for loop alternative, it clearly expresses the intent. "I am filtering this array, using this condition". The functional programming style really shines here, and it shines even more whan you start chaining the operations. I guess the rule of thumb is to write code to most clearly express the intent of it. Often harder said than done but a good goal to strive for.
- collyw 9y agoTo be fair the new arrow operator syntax is a bit cryptic. I am sure Ruby offers plenty of things like that, because when I look at Ruby codebases I often don't understand what they intend to achieve.