Skip to content

Commit 9cf468a

Browse files
committed
extract partitionByIndex
1 parent b41e8fc commit 9cf468a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

source/lib/partition-by-index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @flow
2+
3+
export function partitionByIndex<T>(arr: T[]): [T[], T[]] {
4+
return arr.reduce(
5+
(acc, val, idx) => {
6+
return idx % 2 === 0
7+
? [acc[0].concat(val), acc[1]]
8+
: [acc[0], acc[1].concat(val)]
9+
},
10+
[[], []],
11+
)
12+
}

0 commit comments

Comments
 (0)