Last active
November 14, 2019 20:31
-
-
Save gkucmierz/4fa57dec85f026f1fefe556012129ca4 to your computer and use it in GitHub Desktop.
findIndex, missing findIndexes, prototype, polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findIndexes = (arr, fn) => { | |
const res = []; | |
arr.map((el, i, arr) => { | |
if (fn(el, i, arr)) res.push(i); | |
}); | |
return res; | |
}; | |
// set prototype | |
Array.prototype.findIndexes = function(fn) { | |
return findIndexes(this, fn); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment