Skip to content

Instantly share code, notes, and snippets.

@simontegg
Created July 9, 2022 09:46
Show Gist options
  • Select an option

  • Save simontegg/85c606b00b6d195a5c0d18f5caa8e2c4 to your computer and use it in GitHub Desktop.

Select an option

Save simontegg/85c606b00b6d195a5c0d18f5caa8e2c4 to your computer and use it in GitHub Desktop.
javascript - prettify
/*
Make the function more readable and maintainable
*/
function doStuff(text) {
const lowerCased = text.toLocaleLowerCase();
const words = lowerCased.split(' ');
words.reverse();
const trimmedWords = [];
for (let i in words) {
trimmedWords.push(words[i].trim());
}
const longWords = [];
for (let i in trimmedWords) {
if (trimmedWords[i].length > 5) {
longWords.push(trimmedWords[i]);
}
}
let result = '';
for (let i in longWords) {
result += longWords[i];
result += ', ';
}
return result.slice(0, -2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment