3

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));

1 Answer 1

2

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));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.