Last active
March 24, 2018 03:18
-
-
Save p0rsche/a0a8327d0597a2ee419098766d7e3303 to your computer and use it in GitHub Desktop.
Immutable ES2015 array helpers
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
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