Created
May 29, 2020 06:34
-
-
Save MinSomai/b6a7813d686b17cad19b15c146dbb36a to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Seek and Destroy
This file contains hidden or 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
| function destroyer(arr, ...rest) { | |
| let newArray = [...arr]; | |
| rest.forEach(item=>{ | |
| while(newArray.includes(item)){ | |
| newArray = deleteIfFound(arr, item); | |
| } | |
| }) | |
| return newArray; | |
| } | |
| function deleteIfFound(filterArray, val){ | |
| filterArray.forEach((item, index)=>{ | |
| if(item == val){ | |
| filterArray.splice(index, 1); | |
| } | |
| }); | |
| return filterArray; | |
| } | |
| destroyer([1, 2, 3, 1, 2, 3], 2, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment