Answer to Question #296074 in HTML/JavaScript Web Application for chethan

Question #296074

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

  }


1
Expert's answer
2022-02-11T10:21:11-0500
"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)
  }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS