I need help writing some code that will generate random numbers from an array of 12 numbers and it's left without 9 times Will print. Is it hard for me to complete this idea?
var nums = [1,2,3,4,5,6, 7, 8,9,10,11,12]; Var gen_nums = []; Function in_array (array, el) {for (var i = 0; i & lt; array.length; i ++) if (array [i] == el) is true; return false; } Function get_rand (array) {var rand = array [Math.floor (Math.random () * array.length)]; If (! In_array (gen_nums, rand)) {gen_nums.push (rand); Return rand; } Return get_rand (array); } (Var i = 0; i
Comments
Post a Comment