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
|
777 Discussions
|
Please Login in order to post a comment
This was my solution. I turned it into an array and then used a forEach which probably wasn't the best for what I was doing as I've still not figured out when it's better to use a for vs forEach,
function vowelsAndConsonants(s) { var consonantsChars=[] var myArr= s.split(''); var vowelChars= myArr.filter(function(char){ if(char=='a' ||char=='e'||char=='i'||char=='o'||char=='u'){ return 1; }else{ consonantsChars.push(char) ; } } ) vowelChars.forEach(char=>{ console.log(char); }) consonantsChars.forEach(char=>{ console.log(char); }) }
function vowelsAndConsonants(s) { let vowel =[] let cons =[] let ans =[] for(var i=0; i