Skip to content

Added ugly ES5 equivalent of findIndex - #111

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

jurosh wants to merge 1 commit into
rse:gh-pagesfrom
jurosh:equivalent-to-es6

Conversation

@jurosh

@jurosh jurosh commented Dec 9, 2017

Copy link
Copy Markdown

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

akhoury commented Dec 9, 2017

Copy link
Copy Markdown

findIndex accepts a test function.

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

This branch has not been deployed

No deployments
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