Files
30-seconds-of-code/test/pullAtIndex/pullAtIndex.js
2018-02-04 17:38:39 +02:00

10 lines
274 B
JavaScript

const pullAtIndex = (arr, pullArr) => {
let removed = [];
let pulled = arr
.map((v, i) => (pullArr.includes(i) ? removed.push(v) : v))
.filter((v, i) => !pullArr.includes(i));
arr.length = 0;
pulled.forEach(v => arr.push(v));
return removed;
};
module.exports = pullAtIndex;