We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 2: Loops
Day 2: Loops
Sort by
recency
|
767 Discussions
|
Please Login in order to post a comment
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); }
THIS IS MINE:
To add to the multiple solutions posted, this was my method:
function vowelsAndConsonants(s) {
}
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]) } } }