Reputation: 35
const gotCitiesCSV =
"King's Landing,Braavos,Volantis,Old Valyria,Free Cities,Qarth,Meereen";
let returnOnly = gotCitiesCSV => Array.from(gotCitiesCSV).filter(letter =>
'aa','ee','ii','oo','uu'.includes(letter)).length;
let callElement = document.createElement("div");
callElement.textContent = JSON.stringify(returnOnly)
document.getElementById('kata23').appendChild(callElement)
return returnOnly;
}
When i try to run my code
nothing is returning. So not sure if i am not calling the double vowels correctly. Trying to return the items that has double vowels and as well return as an array instead of a string.
Upvotes: 1
Views: 224
Reputation: 14570
Seems you were nearly there but your logic was a bit wrong. You need to use split
to break cities from comma
and check each individual one against the vowels you have.
Need to use includes
on each string found in filter function so that it can checked if they vowels.
Live Demo:
const gotCitiesCSV = "King's Landing,Braavos,Volantis,Old Valyria,Free Cities,Qarth,Meereen";
let splitStr = gotCitiesCSV.split(',') //split in commas
splitStr.filter(function(x) {
if (x.includes('aa') || x.includes("ee") || x.includes('ii') || x.includes('oo') || x.includes('uu')) {
let callElement = document.createElement("div");
callElement.textContent = JSON.stringify(x)
document.getElementById('kata23').appendChild(callElement)
}
})
<div id="kata23"></div>
Upvotes: 0
Reputation: 12858
Looks like there is a few things going on in that example, but i took a stab at creating a working solution for ya with explanations about whats going on
const gotCitiesCSV =
"King's Landing,Braavos,Volantis,Old Valyria,Free Cities,Qarth,Meereen";
// 1. Array.from() wont split the list of cities into an array
const gotCities = gotCitiesCSV.split(',');
// 2. `returnOnly` is a function, not a result. it looks like you want it to be the result;
const doubleVowels = ['aa','ee','ii','oo','uu'];
const doubleVowelCities = gotCities.filter(
// filter in the cities which
cityName => doubleVowels.some(
// contain some double vowel (i.e., atleast one)
doubleVowel => cityName.includes(doubleVowel),
),
)
which returns
> console.log(doubleVowelCities);
[ 'Braavos', 'Free Cities', 'Meereen' ]
Upvotes: 2