aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/ash/javascript/ch-1.js
blob: 40115ccc9addde6a88f25faa3b0d1f201ba62680 (plain)
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
// Solution of Task 1 of The Weekly Challenge 263
// https://theweeklychallenge.org/blog/perl-weekly-challenge-263/

/*
$ node ch-1.js
[ 1, 2 ]
[]
[ 4 ]
*/

let tests = [
    [1, 5, 3, 2, 4, 2],
    [1, 2, 4, 3, 5],
    [5, 3, 2, 4, 2, 1]
];
let values = [2, 6, 4];

for (let c = 0; c != tests.length; c++) {
    console.log(solve(tests[c], values[c]));    
}

function solve(data, value) {
    data.sort();

    let indices = [];
    for (let c = 0; c != data.length; c++) {
        if (data[c] == value) indices.push(c);
        if (data[c] > value) break;
    }

    return indices;
}