Create a method that creates a new array based on the values ​passed

What is the best way to implement a method that creates a new array based on the values ​​passed. Method entries (3, a), Method result: [‘a’, ‘a’, ‘a’]

It’s a question of an exercise, but I wasn’t able to interpret the question.

I was trying this:

const arr = [];
arr.push(3, 'a');

console.log(arr);

Answer

Very simple Funktion. Just a FOR loop and then array push() function.

function makeArray(num, val) {
    const newArray= [];
  for (let i = 0; i < num; i++) {
    newArray.push(val);
  }
  return newArray;
}

const result = makeArray(3,'a');
console.log(result)