blob: 35d7790240d6810fda8c6a467389946f20700c35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
class Ch1{
countSmaller(integers){
let r = [];
let i = integers;
integers.forEach((x) => {
let smallerCount = integers.map((y) => {return y < x}).
reduce((accumulator, currentValue) => {
return accumulator + currentValue}, 0);
r.push(smallerCount);
});
return r;
}
}
let ch1 = new Ch1();
console.log(
ch1.countSmaller([8, 1, 2, 2, 3])
);
console.log(
ch1.countSmaller([6, 5, 4, 8])
);
console.log(
ch1.countSmaller([2, 2, 2])
);
|