Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active November 14, 2019 20:31
Show Gist options
  • Save gkucmierz/4fa57dec85f026f1fefe556012129ca4 to your computer and use it in GitHub Desktop.
Save gkucmierz/4fa57dec85f026f1fefe556012129ca4 to your computer and use it in GitHub Desktop.
findIndex, missing findIndexes, prototype, polyfill
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