-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflatten.js
38 lines (37 loc) · 1.06 KB
/
flatten.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const test = require("tape");
const { flatten } = require("../");
const {
infiniteIterableOfPositiveIntegers,
testAndToArray,
oneTwoThree,
oneTwoThreeFour,
positiveIntegers,
takeEight,
threeTwoOne,
} = require("./_tools");
test("flatten", (t) => {
const processIterable = testAndToArray(t);
t.deepEqual(
processIterable(flatten([oneTwoThree, threeTwoOne, oneTwoThreeFour])),
[...oneTwoThree, ...threeTwoOne, ...oneTwoThreeFour],
);
t.deepEqual(
processIterable(flatten([1, oneTwoThree, threeTwoOne, oneTwoThreeFour])),
[1, ...oneTwoThree, ...threeTwoOne, ...oneTwoThreeFour],
);
t.deepEqual(
processIterable(
flatten([1, [[[[oneTwoThree]]]], threeTwoOne, oneTwoThreeFour]),
),
[1, ...oneTwoThree, ...threeTwoOne, ...oneTwoThreeFour],
);
t.deepEqual(
processIterable(takeEight(flatten([oneTwoThree, positiveIntegers]))),
[...oneTwoThree, ...oneTwoThreeFour, 5],
);
t.deepEqual(
processIterable(takeEight(flatten(infiniteIterableOfPositiveIntegers))),
[1, 2, 3, 4, 5, 6, 7, 8],
);
t.end();
});