DEV Community

Discussion on: function in JS

Collapse
 
mellen profile image
Matt Ellen

To start with you want to generate a random number based on the length. I see you have a function that will do that, but it seems overly complicated for our needs. I would just use Math.random and Math.ceil, i.e. let newLength = Math.ceil(Math.random()*features.length);

Then you want the new array, for which I would use Array.prototype.slice like so: let portion = features.slice(0, newLength);

Collapse
 
mihel17 profile image
Miguelito

Thank you very much! You`re a true professional