array-future
array-future copied to clipboard
Add negative index support
https://github.com/sindresorhus/negative-array
Related:
- https://github.com/sindresorhus/cycled
Is this possible to implement efficiently?
Without an ES6 Proxy, that is
I do not think so. The reference is for inspiration, but will be difficult bring this feature in the library.
Add others polyfills is not a good idea, because increases considerably the size of the library.
In addition, ES6 Proxy is poor supported, and the current most famous polyfill need special node/browser flags. I would like have this in the library, but too much friction for the final user that is the thing that we try to avoid.
I think the next best thing to negative indexes were if the .last() method could accept (n) and return the [length - n]th element.
@mk-pmb can you provide example of your idea?
function guessScriptFileBeforeCurrent() {
return Array.from(document.getElementsByTagName('script')).last(2).src;
}
I think nowadays make sense ship this feature now that Node.js supports Proxy :)
Added https://github.com/sindresorhus/cycled as inspiration, should be done very similar.
Any PR? 🎉