Created
April 13, 2020 22:44
-
-
Save Nicknyr/0004229da6a66796e4edef3afc8d6367 to your computer and use it in GitHub Desktop.
CodeSignal - Proper Noun Correction
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
/* | |
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