Skip to content

Instantly share code, notes, and snippets.

@kumarparth380
Created February 10, 2022 04:13
Show Gist options
  • Save kumarparth380/71c7b714b8f71023e7ea8ab60d34707b to your computer and use it in GitHub Desktop.
Save kumarparth380/71c7b714b8f71023e7ea8ab60d34707b to your computer and use it in GitHub Desktop.
Replace "$" from array of string and join
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