Skip to content

Instantly share code, notes, and snippets.

@starlabman
Last active October 29, 2022 16:17
Show Gist options
  • Save starlabman/07840c736680f382dc10ef519e884065 to your computer and use it in GitHub Desktop.
Save starlabman/07840c736680f382dc10ef519e884065 to your computer and use it in GitHub Desktop.
Javascript and typescript test
function doStuff(text) {
// Convert the text to lower characters
const lowerCased = text.toLocaleLowerCase();
// Split the characters with the space delimeter
const words = lowerCased.split(' ');
// Reverse split array
words.reverse();
let result = '';
// Check each word in array, trim and return only words with length greater than 5
for (let i in words) {
const trimmedWord = words[i].trim();
if (trimmedWord.length > 5) {
result += trimmedWord;
result += ', ';
}
}
// Remove excess comma and space at end
return result.slice(0, -2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment