Created
November 10, 2017 09:53
-
-
Save fox1t/70fdaaeff474d89e4c1e6ce8eaa457ed to your computer and use it in GitHub Desktop.
Immutable array methods
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
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