Skip to content

Added ugly ES5 equivalent of findIndex#111

Open
jurosh wants to merge 1 commit intorse:gh-pagesfrom
jurosh:equivalent-to-es6
Open

Added ugly ES5 equivalent of findIndex#111
jurosh wants to merge 1 commit intorse:gh-pagesfrom
jurosh:equivalent-to-es6

Conversation

@jurosh
Copy link

@jurosh jurosh commented Dec 9, 2017

I was looking into finding index in array by value - and thinking if it's not possible to do functional way.
So I created this example and I think it's equivalent for ES6 findIndex feature, even though it's so ugly, but it will find the index.

[ 1, 3, 4, 2 ].map(function(x, index) { return x > 3 ? index : undefined; }).filter(function (x) { return x !== undefined; })[0];

-- So everyone can see how easily it's now done in ES6

@akhoury
Copy link

akhoury commented Dec 9, 2017

findIndex accepts a test function.

Also you don't need to iterate twice, see the polyfill for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants