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

20 lines
651 B
JavaScript
Raw Permalink Normal View History

2024-01-05 20:21:36 +00:00
const removeFromArray = function(array, ...remove) {
remove.forEach(element => {
2024-01-05 20:34:14 +00:00
let findIndexElement = array.findIndex(x => x === element);
2024-01-05 20:22:30 +00:00
if (findIndexElement >= 0) {
let saveArray = [];
for (let i = 0, arrayLength = array.length; i < arrayLength - findIndexElement - 1; i++) {
2024-01-05 20:22:30 +00:00
saveArray.push(array.pop());
}
array.pop();
for (let i = 0; i < saveArray.length; i++) {
array.push(saveArray[saveArray.length - 1 - i]);
2024-01-05 20:22:30 +00:00
}
2024-01-05 20:21:36 +00:00
}
});
return array;
};
// Do not edit below this line
module.exports = removeFromArray;