33*/
44
55/**
6- * The TitleCaseConversion converts a string into a title case string.
7- * @param {String } inputString input string
8- * @returns {String }
6+ * The titleCaseConversion function converts a string into a title case string.
7+ * @param {string } inputString The input string which can have any types of letter casing.
8+ * @returns {string } A string that is in title case.
99 */
1010const titleCaseConversion = ( inputString ) => {
1111 // Extact all space seprated string.
1212 const stringCollections = inputString . split ( ' ' ) . map ( word => {
1313 let firstChar = ''
14- // Get a character code by the use charCodeAt method.
14+ // Get the [ASCII](https://en.wikipedia.org/wiki/ASCII) character code by the use charCodeAt method.
1515 const firstCharCode = word [ 0 ] . charCodeAt ( )
16- // If the character code lies between 97 to 122 it means they are in the lower case so convert it.
16+ // If the ASCII character code lies between 97 to 122 it means they are in the lowercase so convert it.
1717 if ( firstCharCode >= 97 && firstCharCode <= 122 ) {
1818 // Convert the case by use of the above explanation.
1919 firstChar += String . fromCharCode ( firstCharCode - 32 )
@@ -22,20 +22,20 @@ const titleCaseConversion = (inputString) => {
2222 firstChar += word [ 0 ]
2323 }
2424 const newWordChar = word . slice ( 1 ) . split ( '' ) . map ( char => {
25- // Get a character code by the use charCodeAt method.
25+ // Get the ASCII character code by the use charCodeAt method.
2626 const presentCharCode = char . charCodeAt ( )
27- // If the character code lies between 65 to 90 it means they are in the upper case so convert it.
27+ // If the ASCII character code lies between 65 to 90, it means they are in the uppercase so convert it.
2828 if ( presentCharCode >= 65 && presentCharCode <= 90 ) {
2929 // Convert the case by use of the above explanation.
3030 return String . fromCharCode ( presentCharCode + 32 )
3131 }
3232 // Else return the characters without any modification.
3333 return char
3434 } )
35- // return the first converted character and remaining character string.
35+ // Return the first converted character and remaining character string.
3636 return firstChar + newWordChar . join ( '' )
3737 } )
38- // convert all words in a string and return it.
38+ // Convert all words in a string and return it.
3939 return stringCollections . join ( ' ' )
4040}
4141
0 commit comments