odin-js-fundamentals-part-4/04_removeFromArray/removeFromArray.js

22 lines
657 B
JavaScript

const removeFromArray = function(array, ...remove) {
remove.forEach(element => {
let findIndexElement = array.findIndex(x => x == element);
if (findIndexElement >= 0) {
let saveArray = [];
for (let i = 0; i < array.length - findIndexElement; i++) {
saveArray.push(array.pop());
}
array.pop();
for (let i = 0; i < saveArray.length; i++) {
array.push(saveArray[saveArray.length - 1 - i]);
}
}
});
return array;
};
removeFromArray([1, 2, 3, 4], 7, 2);
// Do not edit below this line
module.exports = removeFromArray;