Skip to content

Instantly share code, notes, and snippets.

@suryakun
Created February 7, 2023 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suryakun/8dfb7e328cf9693745e44ef147c11e3d to your computer and use it in GitHub Desktop.
Save suryakun/8dfb7e328cf9693745e44ef147c11e3d to your computer and use it in GitHub Desktop.
Simple map reduce
const arr : String[] = ["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"];
function buildTheSentence(arr: String[]) : String {
const result: String = arr
.map((str: String) => (str.match(/[a-zA-Z]/gm) || []).join(''))
.reduce((sentence: String, word : String) => sentence + " " + word )
return result;
}
console.log(buildTheSentence(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment