Otherwise get the value from the map and update right [ i ]
else { let tmp = map . get ( arr [ i ] ) ; right [ i ] = ( tmp . count ) * ( Math . abs ( i - tmp . prevIndex ) ) + right [ tmp . prevIndex ] ; map . set ( arr [ i ] , new pair ( tmp . count + 1 , i ) ) ; } }