Skip to content

Instantly share code, notes, and snippets.

@p0rsche
Last active March 24, 2018 03:18
Show Gist options
  • Save p0rsche/a0a8327d0597a2ee419098766d7e3303 to your computer and use it in GitHub Desktop.
Save p0rsche/a0a8327d0597a2ee419098766d7e3303 to your computer and use it in GitHub Desktop.
Immutable ES2015 array helpers
export const addToArrayImmutable = (arr, value) => [...arr, value]
export const unshiftArrayImmutable = (arr, value) => [value, ...arr]
export const updateArrayImmutable = (arr, i, value) => Object.assign([...arr], {[i]: value})
export const removeFromArrayImmutable = (arr, value) => arr.filter(i => i !== value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment