Created
July 24, 2019 13:49
-
-
Save adixchen/ee826bdd7bcdae9184cd3709b92ef720 to your computer and use it in GitHub Desktop.
Immutable removal of element from list by index
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
const immutableRemoval = (list, index) => { | |
return [ | |
...list.slice(0, index), | |
...list.slice(index+1) | |
]; | |
}; | |
const v = [1,2,3]; | |
console.log(immutableRemoval(v,1)); | |
// [1,3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment