Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created April 13, 2020 22:44
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 Nicknyr/0004229da6a66796e4edef3afc8d6367 to your computer and use it in GitHub Desktop.
Save Nicknyr/0004229da6a66796e4edef3afc8d6367 to your computer and use it in GitHub Desktop.
CodeSignal - Proper Noun Correction
/*
Proper nouns always begin with a capital letter, followed by small letters.
Correct a given proper noun so that it fits this statement.
Example
For noun = "pARiS", the output should be
properNounCorrection(noun) = "Paris";
For noun = "John", the output should be
properNounCorrection(noun) = "John".
*/
function properNounCorrection(noun) {
// Turns the whole word lowercase, pARIS becomes paris
let lowerCaseNoun = noun.toLowerCase();
// Turns the first letter uppercase, p becomes P
let capitalizedFirstLetter = lowerCaseNoun.charAt(0).toUpperCase();
// Turns paris into aris
let removeFirstLetter = lowerCaseNoun.substr(1);
// Concats P with aris to get Paris
return capitalizedFirstLetter + removeFirstLetter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment