forked from TheOdinProject/javascript-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create loop to return non repeating values from array
- Loading branch information
1 parent
f5f453b
commit 02d3f0d
Showing
1 changed file
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
*/ |