That is because Javascript, even though it has the concept of iterables and generators for ages, still does not use them enough.
Take Python, for instance: reversed(x) does not allocate memory if x is randomly indexable. Same for map and filter, which don't execute until you require them. That means:
const [x] = arr(x => x ** 2)
Should only execute the callback ONCE, as we are extracting just the first element. In plain JS, however, it executes for everything and returns a new array.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That is because Javascript, even though it has the concept of iterables and generators for ages, still does not use them enough.
Take Python, for instance:
reversed(x)
does not allocate memory ifx
is randomly indexable. Same formap
andfilter
, which don't execute until you require them. That means:const [x] = arr(x => x ** 2)
Should only execute the callback ONCE, as we are extracting just the first element. In plain JS, however, it executes for everything and returns a new array.