Count the number of vowels occurring in all the substrings of given string | Returns the total sum of occurrences of all vowels ; No . of occurrences of 0 th character in all the substrings ; No . of occurrences of the ith character in all the substrings ; Check if ith character is a vowel ; Return the total sum of occurrences of vowels ; Driver code
function vowel_calc ( s ) { var n = s . length ; var arr = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( i == 0 ) arr . push ( n ) ; else arr . push ( ( n - i ) + arr [ i - 1 ] - i ) ; } var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) sum += arr [ i ] ; return sum ; } var s = " " ; document . write ( vowel_calc ( s ) ) ;