-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathpairPrint.js
More file actions
26 lines (23 loc) · 721 Bytes
/
pairPrint.js
File metadata and controls
26 lines (23 loc) · 721 Bytes
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
// Write a function `pairPrint` that accepts an array as an argument. The function should print
// all unique pairs of elements in the array. The function doesn't need to return any value. It
// should just print to the terminal.
function pairPrint(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
console.log(arr[i], arr[j]);
}
}
}
pairPrint(["artichoke", "broccoli", "carrot", "daikon"]);
// prints
// artichoke - broccoli
// artichoke - carrot
// artichoke - daikon
// broccoli - carrot
// broccoli - daikon
// carrot - daikon
//pairPrint(["apple", "banana", "clementine"]);
// prints
// apple - banana
// apple - clementine
// banana - clementine