-
Notifications
You must be signed in to change notification settings - Fork 13
Sparse arrays case #12
Comments
Very good question. Most ES5 methods, like forEach etc, seem to respect sparsensss, whole most ES6+ methods seem to ignore it. Concptually, while one might expect a sparse array’s “last” item to be the last item it actually contains, i think “length minus one” is probably a simpler and more consistent meaning for it. |
Which ES6 features? All I can think of is destructuring. |
All the ES6+ array iteration methods will interact with every index, present or not, eg:
Also flatten and flatMap will do the same. |
@jridgewell |
Huh, I had no idea those were different (minus iterator). |
I take that seeing it as ES2015+ feature, it should stay as it is, and it was officially stated that spareness should be ignored as a design side effect and not a real feature (hence not supported in all new methods). I rely on util which respects sparseness, but it was implemented that way only to confirm well to ES5 state of things. I don't remember single use case where I would rely on that behavior |
Should it ignore sparse array characteristics?
e.g. if I read current spec, it'll work as:
Similarly with:
Is that expected?
The text was updated successfully, but these errors were encountered: