re-formate TitleCaseConversion method with standard.js

This commit is contained in:
Suryapratap Singh
2021-08-28 13:00:43 +05:30
parent da675fb237
commit 705b1236c8

View File

@ -10,16 +10,16 @@
const TitleCaseConversion = (inputString) => { const TitleCaseConversion = (inputString) => {
// Extact all space seprated string. // Extact all space seprated string.
const stringCollections = inputString.split(' ').map(word => { const stringCollections = inputString.split(' ').map(word => {
let firstChar = ''; let firstChar = ''
// Get a character code by the use charCodeAt method. // Get a character code by the use charCodeAt method.
const firstCharCode = word[0].charCodeAt(); const firstCharCode = word[0].charCodeAt()
// If the character code lies between 97 to 122 it means they are in the lower case so convert it. // If the character code lies between 97 to 122 it means they are in the lower case so convert it.
if(firstCharCode >= 97 && firstCharCode <= 122){ if (firstCharCode >= 97 && firstCharCode <= 122) {
// Convert the case by use of the above explanation. // Convert the case by use of the above explanation.
firstChar += String.fromCharCode(firstCharCode - 32); firstChar += String.fromCharCode(firstCharCode - 32)
}else{ } else {
// Else store the characters without any modification. // Else store the characters without any modification.
firstChar += word[0]; firstChar += word[0]
} }
const newWordChar = word.slice(1).split('').map(char => { const newWordChar = word.slice(1).split('').map(char => {
// Get a character code by the use charCodeAt method. // Get a character code by the use charCodeAt method.
@ -31,12 +31,12 @@ const TitleCaseConversion = (inputString) => {
} }
// Else return the characters without any modification. // Else return the characters without any modification.
return char return char
}); })
// return the first converted character and remaining character string. // return the first converted character and remaining character string.
return firstChar + newWordChar.join(''); return firstChar + newWordChar.join('')
}); })
// convert all words in a string and return it. // convert all words in a string and return it.
return stringCollections.join(' '); return stringCollections.join(' ')
} }
module.exports = TitleCaseConversion; module.exports = TitleCaseConversion