Skip to content

Instantly share code, notes, and snippets.

@MickeyKay
Created April 1, 2018 03:58
Show Gist options
  • Save MickeyKay/eaec0af51e4a6b75be6603aa1ac1150f to your computer and use it in GitHub Desktop.
Save MickeyKay/eaec0af51e4a6b75be6603aa1ac1150f to your computer and use it in GitHub Desktop.
Nested for loop example (better)
var list = ['SoMe', 'hUgE', 'aRrAy', '...'];
// Helper functions
function reverseText(text) {
// A
// big
// chunk
// of
// code
// that
// reverses
// text
}
function capitalizeText(text) {
// A
// big
// chunk
// of
// code
// that
// capitalizes
// text
}
function lowercaseText(text) {
// A
// big
// chunk
// of
// code
// that
// lowercases
// text
}
// Main function (much cleaner, right?)
function reverseAndCapitalizeOrLowercase(list) {
list.forEach(function(text) {
var reversedText = reverseText(text);
if (text.length > 3) {
capitalizeText(text)
} else {
lowercaseText(text)
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment