I want to create 2 random series of 1-10, en divide them into lines of 4. The first 10 have to be in the first lines, and the second 10 next. Important is the lines cannot have double numbers.
Example:
[4,7,3,1]
[10,6,5,2]
[9,8,1,5] // In this line you go from 1st to 2nd serie, an may not contain double numbers
[3,2,9,7]
[4,8,10,6]
For example if i put the numbers in ascending order, to make it more clear:
[1,2,3,4]
[5,6,7,8]
[9,10,1,2] // In this line you go from 1st to 2nd serie, an may not contain double numbers
[3,4,5,6]
[7,8,9,10]
What i have so far:
let arr = [];
let arr2 = [];
for (i = 0; i <=1; i++) {
while (arr.length < 10) {
let r = Math.floor(Math.random() * 10) + 1;
if (arr.indexOf(r) === -1) arr.push(r);
}
arr2.push(arr)
arr = [];
}
console.log(arr2);
But this creates only 2 random array's of 10. I'm stuck from this point, hope someone can help me.
(input values all can be different, series, numberrange and 4 numbers per line)
Aucun commentaire:
Enregistrer un commentaire