Skip to content

Commit

Permalink
Create loop to return non repeating values from array
Browse files Browse the repository at this point in the history
  • Loading branch information
worriedape committed Dec 10, 2024
1 parent f5f453b commit 02d3f0d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion 04_removeFromArray/removeFromArray.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
const removeFromArray = function() {
const removeFromArray = (array, ...deletable) => {
let newArray = [];

outer: for (let x of array) {
for (let item of deletable) {
if (x == item) continue outer;
}
newArray.push(x);
}
return newArray
};

// Do not edit below this line
module.exports = removeFromArray;

/*
iterate on ...deletable
if x from ...deletable is not equal to ...array
return new array without ...deletable
iterate from array,
iterate from ...deletable,
if any of the items from array is not equal
to any of the items from ...deletable,
return it into a new array
removeFromArray([1,2,3], 2)
*/

0 comments on commit 02d3f0d

Please sign in to comment.