Skip to content

Instantly share code, notes, and snippets.

@devlemire
Created June 16, 2016 14:02
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 devlemire/f8fb7f056fa6633f94ca60e9faa6e9bf to your computer and use it in GitHub Desktop.
Save devlemire/f8fb7f056fa6633f94ca60e9faa6e9bf to your computer and use it in GitHub Desktop.
//make a function that takes in a string and capatalizes the first letter of every word and lowercase the rest
function capFirstLetter(str) {
str = str.toLowerCase().split(' ');
for(var i in str) {
str[i] = str[i].split('');
}
for(var j in str) {
var holder = str[j][0].charAt(0).toUpperCase();
str[j][0] = holder;
str[j] = str[j].join('');
}
str = str.join(' ');
console.log(str);
}
capFirstLetter("one two three");
@devlemire
Copy link
Author

devlemire commented Jun 29, 2018

function capFirstLetter(str) {
  str = str.toLowerCase().split(' ')

  str = str.map(word => word[0].toUpperCase() + word.slice(1))

  return str.join(' ')
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment