Very cool, thanks for sharing, Ben! I never knew about array.flat until today. Very neat. 👍
Everyday, I seem to find a new use for array.reduce though. It's seriously the gift that just keeps giving! 😄 Just this morning, I was searching for an equivalent to Python's counter data structure in JS and found this:
Agreed, reduce is for a lot more than just reduce-ing arrays to something smaller (like a number of a string). That's why some languages like Rust and Kotlin call it "fold." That's because you're "folding" something of one data type (like an array) into something of another data type (like a Map in your example). Doesn't mean we've reduced it, we've just changed it into something different!
For further actions, you may consider blocking this person and/or reporting abuse
Very cool, thanks for sharing, Ben! I never knew about
array.flat
until today. Very neat. 👍Everyday, I seem to find a new use for
array.reduce
though. It's seriously the gift that just keeps giving! 😄 Just this morning, I was searching for an equivalent to Python'scounter
data structure in JS and found this:What a beauty! What a time to be alive!! 🚀
Source: stackoverflow.com/a/57028486
Haha yeah, love the enthusiasm 😁
Agreed,
reduce
is for a lot more than justreduce
-ing arrays to something smaller (like a number of a string). That's why some languages like Rust and Kotlin call it "fold." That's because you're "folding" something of one data type (like an array) into something of another data type (like a Map in your example). Doesn't mean we've reduced it, we've just changed it into something different!