words with vowels
the goal of the code is to get output using array method filter()
input
the input will be single line containing an array wordsList
output
the output should be single line containing an array with filtered words
input1
['Sword', 'Myth', 'Patient' ,'Rhythm] output2
['Sword', 'Patient']
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
const wordsList = JSON.parse(readLine().replace(/'/g, '"'));
const vowelsList = ["a", "e", "i", "o", "u"];
// Write your code here
}
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
const wordsList = JSON.parse(readLine().replace(/'/g, '"'));
const vowelsList = ["a", "e", "i", "o", "u"];
// Write your code here
var filterWords = wordsList.filter(function(word){
for (let i in vowelsList) {
if (word.toLowerCase().indexOf(vowelsList[i]) >= 0){
return true
}
}
return false
});
console.log(filterWords)
}
Comments
Leave a comment