odin-default-js-exercises/04_removeFromArray/removeFromArray.js

24 lines
565 B
JavaScript
Raw Normal View History

2023-11-04 11:05:11 +00:00
const removeFromArray = function(arr, ...removeItems) {
let duplicateArray = arr;
console.log('arr duplicates', duplicateArray);
for (let i=0; i < removeItems.length; i++) {
for (let j=0; j < arr.length; j++) {
if(removeItems[i] === arr[j]){
duplicateArray.splice(j, 1);
}
}
}
return duplicateArray;
};
2023-11-04 11:05:11 +00:00
removeFromArray([1, 2, 3, 4], 1, 2, 4);
removeFromArray([1, 2, 3, 4], 3);
removeFromArray([1, 2, 3], "1", 3)
removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)
2017-08-24 13:12:11 +00:00
module.exports = removeFromArray;
2023-11-04 11:05:11 +00:00