Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ugly ES5 equivalent of findIndex #111

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

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