Created
July 9, 2022 09:46
-
-
Save simontegg/85c606b00b6d195a5c0d18f5caa8e2c4 to your computer and use it in GitHub Desktop.
javascript - prettify
This file contains hidden or 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
| /* | |
| 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