Hi I am trying to create an array with paired values from 1-size in random order example : [3,1,1,2,3,2] for size = 3
So far I've done sth like this :
- I fill up both arrays with random numbers when the number isn't already in array
- Repeat for second array
- And then return concatenation of them
I wonder how I can improve the solution of my problem
let arr1 = [];
let arr2 = [];
let number;
let i = 0;
let k = 0;
while (i < size) {
number = Math.floor(Math.random() * size + 1);
if (!arr1.includes(number)) {
arr1.push(number);
i++;
}
}
while (k < size) {
number = Math.floor(Math.random() * size + 1);
if (!arr2.includes(number)) {
arr2.push(number);
k++;
}
}
return arr1.concat(arr2);