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
}
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)
}
Comments
Leave a comment