javascript loop over the alphabet and return the vowels

Solutions on MaxInterview for javascript loop over the alphabet and return the vowels by the best coders in the world

showing results for - "javascript loop over the alphabet and return the vowels"
Jonathan
01 Jan 2021
1function vowelsAndConsonants(s) {
2//Create Array of vowels
3   const vowels = ["a","e","i","o","u"];
4//Convert String to Array
5   const arr = s.split("");
6//Empty vowels and cons array
7   var vowelsFound = [];
8   var cons = [];
9//Push vowels and cons to their arrays
10   for (var i in arr) {
11     if (vowels.includes(arr[i])) {
12        vowelsFound.push(arr[i]);
13        } else {
14            cons.push(arr[i]);
15        }
16   }
17//ConsoleLog so that they in order and cons follows vowels on new lines
18   console.log(vowelsFound.join('\n') + '\n' + cons.join('\n'))
19}
20//Test, Exclude in copy
21vowelsAndConsonants(javascriptloops); 
22