Skip to content

Instantly share code, notes, and snippets.

@sebabouche
Created June 22, 2018 20:21
Show Gist options
  • Save sebabouche/42e0b7cc5b994da6d088df68f7bcf94f to your computer and use it in GitHub Desktop.
Save sebabouche/42e0b7cc5b994da6d088df68f7bcf94f to your computer and use it in GitHub Desktop.
ramda: arrays (nth, slice, contains, head, last, tail, init...)
import {
nth,
slice,
contains,
head,
last,
tail,
init,
length,
take,
takeLast,
insert,
update,
append,
prepend,
concat,
remove,
without,
inc,
adjust,
} from "ramda"
const arr = [0, 1, 3, 7, 14]
console.log("nth(", nth(3, arr))
console.log("contains", contains(7, arr))
console.log("slice", slice(-1, length(arr), arr))
console.log("head", head(arr))
console.log("last", last(arr))
console.log("tail", tail(arr))
console.log("init", init(arr))
console.log("take", take(3, arr))
console.log("takeLast", takeLast(3, arr))
console.log("insert", insert(0, 10, arr))
console.log("update", update(0, 10, arr))
console.log("append", append(10, arr))
console.log("prepend", prepend(10, arr))
console.log("concat", concat([100, 200], arr))
console.log("remove", remove(2, 1, arr))
// console.log("without", without([3], arr))
console.log("update", update(2, inc(nth(2, arr)), arr))
console.log("adjust", adjust(inc, 2, arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment