forked from ehmicky/big-cartesian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (35 loc) · 1.01 KB
/
main.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
39
40
41
// Demo of big-cartesian.
// This file can be directly run:
// - first install `big-cartesian`
// - then `node node_modules/big-cartesian/examples/main.js`
// An online demo is also available at:
// https://repl.it/@ehmicky/big-cartesian
'use strict'
// Ignore the following line: this is only needed for internal purposes.
require('./utils.js')
const bigCartesian = require('big-cartesian')
// Iterate over combinations
// eslint-disable-next-line fp/no-loops
for (const values of bigCartesian([
['red', 'blue'],
['circle', 'square'],
])) {
console.log(values)
}
// [ 'red', 'circle' ]
// [ 'red', 'square' ]
// [ 'blue', 'circle' ]
// [ 'blue', 'square' ]
const generator = function* () {
yield 'circle'
yield 'square'
}
// Notice we pass the function itself: `generator` not `generator()`
// eslint-disable-next-line fp/no-loops
for (const values of bigCartesian([['red', 'blue'], generator])) {
console.log(values)
}
// [ 'red', 'circle' ]
// [ 'red', 'square' ]
// [ 'blue', 'circle' ]
// [ 'blue', 'square' ]