Hacker News new | past | comments | ask | show | jobs | submit login

On point. Even then mentioning it used filter and map. But the bad refactor also uses filter and map. It's the exact same change of programming paradigm.

Given the text, I would have expected some minor refactor with range-based for loops (are these a thing? My JS is rusty). Where you get the advantage of map (no off-by-one indexing errors) without changing the programming paradigm.




you don't even need range loops.

you have forEach:

   list.forEach((item, index) => doSomething());
you also have for/of, though that doesn't have an index if you need that

   for (const item of list) { doSomething() };
which just obviates the need for index incrementing in the most common case, where you are incrementing by one until you hit the end of the list.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: