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
|
// Solution of Task 1 of The Weekly Challenge 263
// https://theweeklychallenge.org/blog/perl-weekly-challenge-263/
/*
$ tsc ch-1.ts
$ node ch-1.js
[ 1, 2 ]
[]
[ 4 ]
*/
const tests = [
[1, 5, 3, 2, 4, 2],
[1, 2, 4, 3, 5],
[5, 3, 2, 4, 2, 1]
];
const values = [2, 6, 4];
for (let c = 0; c != tests.length; c++) {
console.log(solve(tests[c], values[c]));
}
function solve(data: number[], value: number) {
data.sort();
let indices: number[] = [];
for (let c = 0; c != data.length; c++) {
if (data[c] == value) indices.push(c);
if (data[c] > value) break;
}
return indices;
}
|