Created
February 10, 2022 04:13
-
-
Save kumarparth380/71c7b714b8f71023e7ea8ab60d34707b to your computer and use it in GitHub Desktop.
Replace "$" from array of string and join
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ourVision = [ | |
"B$u$i$ld", | |
"$t$$h$e", | |
"N$e$x$t", | |
"E$$ra", | |
"$$o$f$", | |
"S$$of$t$wa$r$e", | |
"De$$ve$l$op$me$n$t", | |
]; | |
// Solution 1 | |
console.log(ourVision.join(" ").toUpperCase().replaceAll("$", "")); | |
// -> BUILD THE NEXT ERA OF SOFTWARE | |
// Solution 2 (without using .join() & .replaceAll()) | |
var result = ourVision.reduce((acc, curr) => { | |
for (let index = 0; index < curr.length; index++) { | |
if (curr[index] != "$") acc += curr[index].toUpperCase(); | |
} | |
acc += " "; | |
return acc; | |
}, ""); | |
console.log(result); | |
// -> BUILD THE NEXT ERA OF SOFTWARE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment