modemean
//Challenge 1
function modemean(array)
{
let max = 0 ;
let mean = 0 ;
for( let i = 0 ; i < array.length ; i++ )
{
mean += array[i] ;
if ( array[i] > max )
max = array[i] ;
}
mean /= array.length ;
const arr = Array.from({ length: max+1 }).fill(0) ;
for( let i = 0 ; i < array.length ; i++ )
arr[array[i]]++ ;
max = 0;
for( let i = 0 ; i <arr.length ; i++ )
if( arr[i] > max )
max = i ;
if( Math.floor(mean) === max )
return true ;
return false ;
}
console.log( modemean([ 9 , 9 , 9 , 9 , 9 ]) ) ;