Skip to content

Instantly share code, notes, and snippets.

@nash403
Created November 10, 2017 07:17
Show Gist options
  • Save nash403/f98b6d88ebcc915e3d163392aa15ba32 to your computer and use it in GitHub Desktop.
Save nash403/f98b6d88ebcc915e3d163392aa15ba32 to your computer and use it in GitHub Desktop.
Immutable array utils
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)
delete = i => x => [...x.slice(0,i), ...x.slice(0,i+1)]
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