Skip to content

Instantly share code, notes, and snippets.

@adixchen
Created July 24, 2019 13:49
Show Gist options
  • Save adixchen/ee826bdd7bcdae9184cd3709b92ef720 to your computer and use it in GitHub Desktop.
Save adixchen/ee826bdd7bcdae9184cd3709b92ef720 to your computer and use it in GitHub Desktop.
Immutable removal of element from list by index
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