Challenge: Find the number that appears most frequently in the array!
Use Javascript to find which number in the starter code array is the most common.
Good luck!
| var numbers = [1,3,73,5,3,7,9,6,4,6,8,0,8,6,5,4,32,4,5,6,8,9,0,9,7,6,4,3,2,4,6,7,7,9,6,5,3,4,6,7,8,0,0,9,7,4,4,3,2,3,4,5,6,7,8,9,0,0,9,8,6,4,1]; | |
| var occurences = []; | |
| var incrementor = 0; | |
| var max_val; | |
| var find_most_frequent = function(){ | |
| for(var i = 0; i < numbers.length; i++){ | |
| for(var oc = 0; oc < numbers.length; oc++){ | |
| if(numbers[i] == numbers[oc]){ | |
| incrementor ++; | |
| } | |
| } | |
| occurences.push(incrementor); | |
| incrementor = 0; | |
| } | |
| max_val = numbers[occurences.indexOf(Math.max.apply(Math, occurences))]; | |
| return max_val; | |
| } | |
| console.log(find_most_frequent()); |
| var numbers = [1,3,73,5,3,7,9,6,4,6,8,0,8,6,5,4,32,4,5,6,8,9,0,9,7,6,4,3,2,4,6,7,7,9,6,5,3,4,6,7,8,0,0,9,7,4,4,3,2,3,4,5,6,7,8,9,0,0,9,8,6,4,1]; | |
| // Place solution here |