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

Question #296081

Selected words to Uppercase

the goal of this code to get output using string methods startsWith(), endsWith() and toUpperCase()


convert uppercase if a string in wordsList starts or ends with the given myString

log the array containg the converted strings in the console


input

the first line containing an array wordsList

second line containing a string myString

output

the output should be single line containing an array with converted strings


input1

['absolute','umbrella','achivement','formula']

a

output1

['ABSOLUTE', 'UMBERELLA','ACHIVEMENT','FORMULA']


function readLine() {

 return inputString[currentLine++];

}


function main() {

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

 const myString = readLine();


/* Please do not modify anything above this line */

  

 // Write your code here


}


1
Expert's answer
2022-02-12T09:44:14-0500
function readLine() {
    return inputString[currentLine++];
}
   
function main() {

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

    /* Please do not modify anything above this line */
    // Write your code here

    const newWordsList = wordsList.map((word) => {
        if (word.startsWith(myString) || word.endsWith(myString))
            return word.toUpperCase()
        else
            return word
    })
    
    console.log(newWordsList)

}

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