Simplify indexOfAll

This commit is contained in:
Siarhei
2018-08-02 15:36:36 +04:00
parent 1cffc77bd9
commit f634531b44
2 changed files with 3 additions and 11 deletions

View File

@ -1,6 +1,2 @@
const indexOfAll = (arr, val) => {
const indices = [];
arr.forEach((el, i) => el === val && indices.push(i));
return indices;
};
const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => el === val ? [...acc, i] : acc, []);
module.exports = indexOfAll;