Last active
September 12, 2022 12:01
-
-
Save argyleink/dd2332b52f698c4c8647d27bba415d1b to your computer and use it in GitHub Desktop.
immutable array examples
This file contains 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 => [...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)] | |
const unique = arr => [...new Set(arr)] | |
const {0:first, length:l, [l - 1]:last} = [1,2,3,4,5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: