Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
Created June 23, 2020 07:36
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 robinpokorny/140d3a4789459039833d1db280eb2e1d to your computer and use it in GitHub Desktop.
Save robinpokorny/140d3a4789459039833d1db280eb2e1d to your computer and use it in GitHub Desktop.
For vs map/filter/reduce
const words = ["hello", " ", "world"];
for (let i = 0; i <= words.length; i++) {
const word = words[i];
if (word.length <= 0) continue;
words[i] = uppercaseFirstLetter(word.trim());
}
const titlecasedWords = words
.filter(isNotEmpty)
.map(trim)
.map(uppercaseFirstLetter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment