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
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 ifxis randomly indexable. Same formapandfilter, 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.