Is it possible to fill an array with a specific number of elements, determined by a given function parameter? The task is to populate myArray with 5 numbers within the range of 5 and 15.
function populateArray(num, startValue, endValue){
var j,
localArray=[];
for(j=startValue;j<=endValue;j+=1){
var k = Math.floor(Math.random()* j);
localArray.push(k);
}
console.log(localArray);
}
The 'num' parameter specifies the number of elements desired in the array – any ideas on how to achieve this? Your help is greatly appreciated!