JSFiddle - React, Tailwind, and code Playground
by Alexander Zonov
Babel + JSX
function implementation (listOfNumbers, howMuchBiggestToTake) {
if (listOfNumbers.length <= howMuchBiggestToTake) {
return listOfNumbers;
} else {
var sandBox = [];
listOfNumber.map((n) => {
let fromZero = 0;
if (!sandBox[fromZero]) {
sandBox[fromZero] = [n];
return;
}
// TODO: add recursion here to avoid a lot of counters
for (let grade of sandbox) {
if (firstFrom(grade) >= n) {
grade.push(n);
break;
}
if ()
}
});
return listOfNumbers;
}
}
function test() {
var first = [
[ 3, 5, 6, 6 ].sort( random ),
5
];
print(
'first -> ',
implementation(first[0], first[1]) === first[0]
);
var second = [
[ 4, 5, 6, 12].sort( random ),
3
]
print(
'second -> ',
implementation(second[0], second[1]).sort() === [5, 6, 12]
);
}
function print (string, ...rest) {
var text = [string, ...rest];
console.log(text.join(' '));
document.body.appendChild(document.createTextNode(text.join(' ')));
document.body.appendChild(document.createElement('br'));
}
/*
Not a random for real
*/
function random () {
return Math.random() - 0.5;
}
function firstFrom (list) {
return list[0];
}
function lastFrom (list) {
return list[list.length - 1];
}
try {
window.console.clear();
test();
} catch (e) {
alert(e);
}