-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathprintCombination.js
32 lines (29 loc) · 914 Bytes
/
printCombination.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
// Write a function `printCombinations`that accepts two arrays as arguments. The function should
// print all combinations of the elements generated by taking an element from the first array and
// and an element from the second array. The function doesn't need to return any value. It
// should just print to the terminal.
function printCombinations(array1, array2) {
for (let i = 0; i < array1.length; i++) {
const element1 = array1[i];
for (let j = 0; j < array2.length; j++) {
let element2 = array2[j];
console.log(element1, element2);
}
}
}
let colors = ["gray", "cream", "cyan"];
let clothes = ["shirt", "flannel"];
printCombinations(colors, clothes);
// prints
// gray shirt
// gray flannel
// cream shirt
// cream flannel
// cyan shirt
// cyan flannel
//printCombinations(["hot", "cold"], ["soup", "tea"]);
// prints
// hot soup
// hot tea
// cold soup
// cold tea