map and freqOfMode are together used to keep track of the frequency of the most occurring element in [ 0. . i ]
let freq = new Array ( 100000 ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } let freqOfMode = 0 ; for ( let it = 0 ; it <= i ; it ++ ) { freq [ ar [ it ] ] ++ ; let newElementFreq = freq [ ar [ it ] ] ; if ( newElementFreq > freqOfMode ) freqOfMode = newElementFreq ; }