Skip to content
Discussion options

You must be logged in to vote

Is the map() going to actually allocate and construct an entire huge intermediate array, or is some kind of magic going to skip that?

As you suggest, for each function call you actually end up with a new array being allocated.

In theory with ES6 iterators you could avoid this, but they're not implemented in Espruino at the moment.

In your example, map->filter->forEach, yes, it'd be faster/more efficient to just combine the code into one function unless you had a specific reason not to (like code re-use).

A lot of it really depends on the size of your array though. If you've got 100 elements in the array it doesn't really matter if you temporarily allocate a new one and it's more about r…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mdoggydog
Comment options

Answer selected by mdoggydog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants