In this HackerRank Day 2: Loops 10 days of javascript problem solution First, print each vowel in s on a new line. The English vowels are a, e, i, o, and u, and each vowel must be printed in the same order as it appeared in s.
Second, print each consonant (i.e., non-vowel) in s on a new line in the same order as it appeared in s.


HackerRank Day 2: Loops problem solution


Problem solution in JavaScript programming.

/*
 * Complete the vowelsAndConsonants function.
 * Print your output using 'console.log()'.
 */
function vowelsAndConsonants(s) {
    var vows = [];
    var cons = [];

    for (var i = 0; i < s.length; i++) {
        if ('aeiou'.includes(s[i])) {
            vows.push(s[i]);
        } else {
            cons.push(s[i]);
        }
    }
    
    console.log(vows.join("\n"));
    console.log(cons.join("\n"));
    
}