words with vowels
The goal of this coading exam is to quickly get you off the ground with the array method filter().
given vowel list in the prefilled code and wordList as input,write a js program to,
filrer the words from wordslist with at least one vowel in it
log the array containning the filtered words in the console
input:
['Sword' , 'Myth' , 'Patient', 'Rhythm']
output:
['Sword', 'Patient']
input:
['Road' , 'Printer' , 'Eye' , 'Hymn']
output:
['Road' , 'Printer' , 'Eye' ]
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<script>
let arr1 = ['Sword' , 'Myth' , 'Patient', 'Rhythm'];
let arr2 = ['Road' , 'Printer' , 'Eye' , 'Hymn'];
vowelListFilter(arr1);
vowelListFilter(arr2);
function vowelListFilter(arr) {
let res = arr.filter(item => {
let test = false;
for (let i = 0; i < item.length; i++) {
if (['a', 'e', 'i', 'o', 'u'].includes(item[i].toLowerCase())) {
test = true;
}
}
return test;
})
console.log(res);
}
</script>
</body>
</html>
Comments
Leave a comment