MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / upperCaseConversion

Function upperCaseConversion

Conversions/UpperCaseConversion.js:18–33  ·  view source on GitHub ↗
(inputString)

Source from the content-addressed store, hash-verified

16 * @returns {string} Uppercase string
17 */
18const upperCaseConversion = (inputString) => {
19 // Take a string and split it into characters.
20 const newString = inputString.split('').map((char) => {
21 // Get a character code by the use charCodeAt method.
22 const presentCharCode = char.charCodeAt()
23 // If the character code lies between 97 to 122, it means they are in the lowercase so convert it.
24 if (presentCharCode >= 97 && presentCharCode <= 122) {
25 // Convert the case by use of the above explanation.
26 return String.fromCharCode(presentCharCode - 32)
27 }
28 // Else return the characters without any modification.
29 return char
30 })
31 // After modification, with the help of the join method, join all the characters and return them.
32 return newString.join('')
33}
34
35export { upperCaseConversion }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected