Hacker News new | ask | show | jobs
by feupan 1596 days ago
Sorry but bad article. It resolves with a “range()” function and then uses for-of to call it: that’s not functional programming.

Then every for-of loop example does not execute anything because it’s creating an inline arrow function without calling it.

1 comments

What I also noticed was one of the problems the author claims that "imperative" style loops have:

>Off-by-one bugs are more probable. For example, you might write i<22 instead, and then the loop would end at 21, not 22.

Ironically, their implementation of a function called "range" differs from the (likely) best known function by that name (that of Python), causing exactly this problem. (Also, the Pythonic range is probably a better fit for a language with 0-based indexing.)

If anyone needs a typed JS version of Python's range, I prepared this code to be a 1:1 match with the Python API. It also uses generators: https://github.com/graup/pythonic-ts/blob/main/src/iterators...