Skip to content

Commit

Permalink
refactor: Extract some array helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jul 7, 2020
1 parent ea895b4 commit c62c614
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const range = (a, b) => [...Array(b + 1).keys()].slice(a);

export const partition = (arr, predicate) =>
arr.reduce(
([truthy, falsey], item) =>
predicate(item)
? [truthy.concat(item), falsey]
: [truthy, falsey.concat(item)],
[[], []]
);

0 comments on commit c62c614

Please sign in to comment.