-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcount-triplets.js
64 lines (52 loc) · 1.16 KB
/
count-triplets.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
*
* ----------------
* | COUNT TRIPLETS |
* ----------------
*
*
* You are given an array of integers and `r`. Where `r`
* is a ratio. The `r` of 1 and 4 is 4, the `r` of 2 and 4 is 2, etc.
*
* You need to find three different indexes (i,j,k) where the values
* at those indexes all have `r` ratio and they are i<j<k.
*
* Find all the triplet indexes that meet these criteria.
*
* EDGE CASES
* - duplicate values?
* - count a triplet for each repeated value
* - negatives?
*
* e.g.
*
* numArr = [1, 3, 9, 9, 27, 81]
* r = 3
*
* countTriplets.js(numArr, r) // returns 6
*
*
*
* */
/*
*
* ***** SOLUTION
*
* */
function countTriplets(numsArr, r) {
return numsArr;
};
/*
* ***** TESTS
*
* */
const numsArr1 = [1, 2, 2, 4]
const r1 = 2
console.log("## TEST 1 ----- > ", countTriplets(numsArr1, r1)); // 6
// const numsArr1 = [1, 3, 9, 9, 27, 81]
// const r1 = 3
// console.log("## TEST 1 ----- > ", countTriplets(numsArr1, r1)); // 6
// const numsArr2 = null;
// console.log("## TEST 2 ----- > ", countTriplets(numsArr2)); // 100
// const numsArr3 = null;
// console.log("## TEST 3 ----- > ", countTriplets.js(numsArr3)); // 128