Function to return max_element index
function max_element ( arr ) { let idx = 0 ; let max = arr [ 0 ] ; for ( let i = 1 ; i < arr . length ; i ++ ) { if ( max < arr [ i ] ) { max = arr [ i ] ; idx = i ; } } return idx ; }