JSFiddle - React, Tailwind, and code Playground

by Ronny

JavaScript

var bag = [function(){console.log('0')}, function(){console.log('1')}, function(){console.log('2')}, function(){console.log('3')}, function(){console.log('4')}, function(){console.log('5')}, function(){console.log('6')}, function(){console.log('7')}];

var randoms = [];
var velocity = Math.floor( Math.random() * 10 );
for(var i = 0; i < velocity; i++) {
var level = Math.floor( Math.random() * bag.length );
    if(randoms.indexOf(level) > -1){ i-- } else { randoms.push(level) };
}

console.log('velocity', velocity, randoms);
var active = [];
for(var j = 0; j < randoms.length; j++) {
    active.push(bag[randoms[j]]);
    // just for verifying
    bag[randoms[j]]();
}

console.log(active);