Skip to content

Instantly share code, notes, and snippets.

@wheresrhys
Last active July 27, 2018 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheresrhys/dbb499b0e85daff37d6f71d421c68a54 to your computer and use it in GitHub Desktop.
Save wheresrhys/dbb499b0e85daff37d6f71d421c68a54 to your computer and use it in GitHub Desktop.
You might not need lodash

You might not need lodash

_.chunk

(arr, size) => [...Array(Math.ceil(arr.length/size))].map(() => arr.splice(0, size))

_.compact

(arr) => arr.filter(it => !!it)

_.concat

(arr, values) => arr.concat(...values)

_.difference

(arr1, arr2) => arr1.filter(item => !arr2.includes(item))

_.differenceBy

(arr1, arr2, func) => { const comparer = arr2.map(func); return arr1.filter(item => !comparer.includes(func(item))) }

_.differenceWith

(arr1, arr2, func) => arr1.filter(item => !arr2.some(otherItem => func(item, otherItem)))

_.drop(array, [n=1])

(arr, n = 1) => arr.slice(n)

_.dropRight(array, [n=1])

(arr, n = 1) => arr.slice(0, -n)

.dropRightWhile(array, [predicate=.identity])

(arr, func = a => a) => arr.slice().reverse().reduce((result, item, i) => result ? result : (!func(item) && arr.slice(0, -i)), null)

.dropWhile(array, [predicate=.identity])

(arr, func = a => a) => arr.reduce((result, item, i) => result ? result : (!func(item) && arr.slice(i)), null)

_.fill(array, value, [start=0], [end=array.length])

(arr, val, start = 0, end) => { end = end || arr.length; const copy = arr.slice() copy.splice(start, end, [...Array(start - end)].map(() => val) return copy; }

.findIndex(array, [predicate=.identity], [fromIndex=0])

(arr, func = a => a, from = 0 ) => arr.slice(from).findIndex(func) + from

_.findLastIndex

_.first -> head

_.flatten

_.flattenDeep

_.flattenDepth

_.fromPairs

_.head

_.indexOf

_.initial

_.intersection

_.intersectionBy

_.intersectionWith

_.join

_.last

_.lastIndexOf

_.nth

_.pull

_.pullAll

_.pullAllBy

_.pullAllWith

_.pullAt

_.remove

_.reverse

_.slice

_.sortedIndex

_.sortedIndexBy

_.sortedIndexOf

_.sortedLastIndex

_.sortedLastIndexBy

_.sortedLastIndexOf

_.sortedUniq

_.sortedUniqBy

_.tail

_.take

_.takeRight

_.takeRightWhile

_.takeWhile

_.union

_.unionBy

_.unionWith

_.uniq

_.uniqBy

_.uniqWith

_.unzip

_.unzipWith

_.without

_.xor

_.xorBy

_.xorWith

_.zip

_.zipObject

_.zipObjectDeep

_.zipWith

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment