Append index corresponding to arr [ i ] in the map
for ( let i = 0 ; i < arr . length ; i ++ ) { if ( M . has ( arr [ i ] ) ) { M . get ( arr [ i ] ) . push ( i ) ; } else { M . set ( arr [ i ] , [ i ] ) } }