Skip to content

Instantly share code, notes, and snippets.

@fox1t
Created November 10, 2017 09:53
Show Gist options
  • Save fox1t/70fdaaeff474d89e4c1e6ce8eaa457ed to your computer and use it in GitHub Desktop.
Save fox1t/70fdaaeff474d89e4c1e6ce8eaa457ed to your computer and use it in GitHub Desktop.
Immutable array methods
const clone = x => [...x]
const push = y => [...x, y]
const pop = x = > x.slice(0, -1)
const unshift = y => x => [y, ...x]
const shift = x => x.slice(1)
const sort = f => x => [...x].sort(f)
const delete = i => x => [...x.slice(0, i), ...x.slice(i+1)]
const splice = (s, c, ...y) => x => [...x.slice(0, s), ...y, ...x.slice(s + c)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment