Sort by

recency

|

767 Discussions

|

  • + 0 comments

    This is mine

    const isVowel = (caracter) => ['a','e','i','o','u'].includes(caracter); const printVowel = (caracter) => isVowel(caracter) && console.log(caracter); const printConsonant = (caracter) => !isVowel(caracter) && console.log(caracter); const textLength = (text) => text.length;

    const mapText = (text, vowel) => { var i = 0; while(i < textLength(text)){ vowel ? printVowel(text[i]): printConsonant(text[i]);
    i++; } }

    function vowelsAndConsonants(s) {
    mapText(s, true); mapText(s, false); }

  • + 0 comments

    THIS IS MINE:

    function vowelsAndConsonants(s) {
        const VOWLES = new Set(['a', 'e', 'i', 'o', 'u']);
        let sConsonants = '';
        
        for (let char of s) {
            VOWLES.has(char) ? console.log(char) : sConsonants += char + '\n';
        }
    
        console.log(sConsonants);
    }
    
  • + 0 comments

    To add to the multiple solutions posted, this was my method:

    function vowelsAndConsonants(s) {

    const vowelArray = ["a", "e", "i", "o", "u"];
    let outputVowel = ""; 
    let outputConsonant = ""; 
    
    for (let i = 0, len = s.length; i < len; i++) {
    
        if (vowelArray.includes(s[i])) {
            outputVowel += s[i] + '\n';
        } else {
            outputConsonant += s[i] + '\n';
    
        }
    
    }
    
    console.log(outputVowel + outputConsonant)
    

    }

  • + 0 comments
    function vowelsAndConsonants(s) {
        let vowelsArray = ['a','e','i','o','u'];
        let vowels = []
        let consonants = []
    
        for(let char of s) {
            vowelsArray.includes(char) ? vowels.push(char) : consonants.push(char)
        }
    
        let vowels_and_consonant = [...vowels, ...consonants]
        vowels_and_consonant.forEach(elem => console.log(elem))
    
    }
    
  • + 0 comments

    Newby, doing things very slowly, but thouroughly. Method goes throught the string twice, Once for vowels, and second time for consonants.

    function vowelsAndConsonants(s) { for (let x = 0; x < s.length; x++){ if(s[x]=='a' || s[x]=='e' || s[x]=='i' || s[x]=='o' || s[x]=='u'){ console.log(s[x]) } } for (let x = 0; x < s.length; x++){ if (s[x]!='a' && s[x]!='e' && s[x]!='i' && s[x]!='o' && s[x]!='u'){ console.log(s[x]) } } }