News for hackers. Stuff that matters.
Re:LeftPad and Go: can tooling help? by nailer on Friday April 01, 2016 @09:02AM (#11404440)
> 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

There are no comments on this comment yet.