Store the indices which contains the vowels
var indices = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { if ( counts . has ( s [ i ] ) ) counts . set ( s [ i ] , counts . get ( s [ i ] ) + 1 ) else counts . set ( s [ i ] , 1 ) indices . push ( i ) ; } }