Refactor Maps (#2)

This commit is contained in:
gavin
2018-07-17 21:28:17 +00:00
committed by Gitea
parent 0545c0a5d9
commit 57ada13a8d
13 changed files with 167 additions and 86 deletions

View File

@@ -64,6 +64,12 @@ export function find (obj, predicate) {
}
}
export function flatten (list) {
if (Array.isArray(list)) {
return list.reduce((memo, element) => memo.concat(Array.isArray(element) ? flatten(element) : element), []);
}
}
export function forEach (obj, iteratee) {
if (Array.isArray(obj)) {
// native 'forEach' but the return below allows us to chain
@@ -250,6 +256,7 @@ export let _ = {
contains,
filter,
find,
flatten,
forEach,
groupBy,
identity,