Can someone help me? I would like to make a simple code where dom generates a random number from 0-14 and adds it to the ran array and it will only stop once all numbers from 0-14 are inside the array.
function random () {
let ran = []
let dom = Math.floor(Math.random() * 15)
while (a != a.length(15)) {
a.push(b)
return a
}
}
console.log(random)
Logic.
random function keeps on pushing random mnumbers from 0-14 to the ran arraycheckAllNumberpresent creates a number array from 0 - 14 using Array.from(Array(15).keys())numberArrayfalse and this stops the while loop execution.Working Fiddle
function checkAllNumberpresent(arr) {
const numberArray = Array.from(Array(15).keys());
const missingNodes = numberArray.filter(item => arr.indexOf(item) === -1);
return missingNodes.length == 0;
}
function random() {
const ran = [];
while (!checkAllNumberpresent(ran)) {
let dom = Math.floor(Math.random() * 15);
ran.push(dom)
}
return ran
}
console.log(random())