Here is the code, it uses map to go through and do the function. However if I want to make it do a loop using for (let i = 0) how would I go about that?
function randomArrayGenerator(n, low, high) {
var randoms = [...Array(n)].map(() => Math.random() * (high - low) + low);
return randoms;
}
console.log(randomArrayGenerator(10, 23, 51));
By this way
function randomArrayGenerator(n, low, high) {
let randoms = [];
for(let i = 0; i < n; i++) {
randoms.push(Math.random() * (high - low) + low);
}
return randoms;
}
console.log(randomArrayGenerator(10, 23, 51));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With