Skip to content

Instantly share code, notes, and snippets.

@marcusandre
Created November 13, 2017 07:48
Show Gist options
  • Save marcusandre/4b461d11dbb861fc1233de61b3363a13 to your computer and use it in GitHub Desktop.
Save marcusandre/4b461d11dbb861fc1233de61b3363a13 to your computer and use it in GitHub Desktop.
Immutable array operations
clone = x => [...x]
push = y => x => [...x, y]
pop = x => x.slice(0, -1)
unshift = y => x => [y, ...x]
shift = x => x.slice(1)
sort = f => x => [...x].sort(f)
del = i => x => [...x.slice(0, 1), ...x.slice(i + 1)]
splice = (s, c, ...y) => x => [...x.slice(0, s), ...y, ...x.slice(s + c)]
@marcusandre
Copy link
Author

  • run perf tests against original array methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment