4 ms·
Just wanting to say that all JS solutions are quite 'bad', except the simple for-of, because they're combining pure array methods (.map, .reduce) and side-effec
by 11235813213455 6y ago
Just wanting to say that all JS solutions are quite 'bad', except the simple for-of, because they're combining pure array methods (.map, .reduce) and side-effects (external variable to that method), not even talking about modifying Array protoype https://github.com/josevalim/nested-data-structure-traversal/blob/master/javascript/map_with_state.js#L3 https://github.com/josevalim/nested-data-structure-traversal..., never do this, don't touch to objects you don't own, and that others would access and not expect to be modified!
I'll make a PR to try to contribute, instead of just complaining like that, hehe
Btw I'm surprised the structure isn't deeply nested (requiring recursion to process it), it'd be more interesting
- saiojd 6y agoFor the sake of argument, there's really nothing wrong with combining map/reduce with side-effects, especially for things like counters were the alternative of threading the variables everywhere can end up being much more complex very quickly.
- zdragnar 6y agoFor the sake of argument, use `forEach` if you want to introduce side effects. `map` and `reduce` are names with meaning, and passing impure functions to them is more confusing than passing some procedural function to `forEach` or using `for of`. It is something of a nit-picky argument to be sure, but it is a good mental habit to have. Edit: I think being strict with the semantic building blocks is a good mental habit, not necessarily making nit-picky arguments.
- the-smug-one 6y agoBeing disciplined is part of good engineering. To have clearly defined idioms is important, so I want to reinforce that this is not nit-picky. You can argue that anything is nit-picky, under the guise of subverting good engineering in exchange for getting to be lazy.