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

Question #295279

write a JS program to

  • filter the candidates who have scored more than 75 points in every even


input

  • the input will be single line containing an array of objects candidatesList

output

  • the output should be single line containing an array with names of the selected candidates.


input1

[{'name': 'Blake Hodges', 'points':[76, 98, 88, 84]}

output1

['Blake Hodges]


"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 candidatesList = JSON.parse(readLine().replace(/'/g, '"'));



  

 // Write your code here

}



1
Expert's answer
2022-02-09T14:53:59-0500
function main() {


    const candidatesList = JSON.parse(readLine().replace(/'/g, '"'));


    // Write your code here
    const candidates = candidatesList.filter((candidate) => {
        if (candidate.points.filter((point) => point > 75).length === 4) return candidate
    }).map((candidate) => candidate.name)


    return candidates


}

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