3 ms·
Like checking if the thing at hand is an array? Or a positive integer? Or iterating through hash's keys? Or another implementation of reduce()/fold()? Why won'
by dozzie 11y ago
Like checking if the thing at hand is an array? Or a positive integer? Or iterating through hash's keys? Or another implementation of reduce()/fold()?
Why won't you outsource your condition checking to a well-tested wrapper around if-else?
- nailer 11y ago> Like checking if the thing at hand is an array? Yes. ES6 has isArray(). Use a well known polyfill rather than write your own for ES5 environments. > Or a positive integer? Yes. As discussed there are edge cases around negative 0 that you may not think of. > Or iterating through hash's keys? Personally, yes, but not necessarily. There's 'for of' which iterates over an Object's own keys - I'm presuming you know regular 'for in' iteration iterates over parent prototype keys and why that's often unwanted - but 'for of' is relatively new. I prefer an approach more consistent with how arrays are handled, so I use Object.prototype.[someprefix]forEach() and share the code. > Why won't you outsource... Using libraries isn't outsourcing. Please read https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html