array-future icon indicating copy to clipboard operation
array-future copied to clipboard

Add negative index support

Open Kikobeats opened this issue 9 years ago • 7 comments

https://github.com/sindresorhus/negative-array

Related:

  • https://github.com/sindresorhus/cycled

Kikobeats avatar Jun 06 '15 12:06 Kikobeats

Is this possible to implement efficiently?

lukewestby avatar Jun 06 '15 16:06 lukewestby

Without an ES6 Proxy, that is

lukewestby avatar Jun 06 '15 16:06 lukewestby

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.

Kikobeats avatar Jun 06 '15 16:06 Kikobeats

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 avatar Aug 05 '16 00:08 mk-pmb

@mk-pmb can you provide example of your idea?

Kikobeats avatar Aug 05 '16 20:08 Kikobeats

function guessScriptFileBeforeCurrent() {
  return Array.from(document.getElementsByTagName('script')).last(2).src;
}

mk-pmb avatar Aug 05 '16 22:08 mk-pmb

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? 🎉

Kikobeats avatar Sep 11 '18 18:09 Kikobeats