Sort an Array of Strings according to the number of Vowels in them | Function to check the Vowel ; Returns count of vowels in str ; if ( isVowel ( str [ i ] ) ) Check for vowel ; Function to sort the array according to the number of the vowels ; Vector to store the number of vowels with respective elements ; Inserting number of vowels with respective strings in the vector pair ; Sort the vector , this will sort the pair according to the number of vowels ; Print the sorted vector content ; Driver code
function isVowel ( ch ) { ch = ch . toUpperCase ( ) ; return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function countVowels ( str ) { let count = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) ++ count ; return count ; } function sortArr ( arr , n ) { let vp = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { vp . push ( [ countVowels ( arr [ i ] ) , arr [ i ] ] ) ; } vp . sort ( ) ; for ( let i = 0 ; i < vp . length ; i ++ ) document . write ( vp [ i ] [ 1 ] + " " ) ; } let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; sortArr ( arr , n ) ;