Find the maximum element in the array
var k = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var m = Array ( k ) . fill ( 0 ) ; arr . forEach ( n => { ++ m [ n ] ; } ) ; for ( var n = arr . length ; n > 0 ; -- n ) { if ( n == m [ n ] ) return n ; } return - 1 ; }