mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
Fix typos and update description to include a link
This commit is contained in:
@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
Explanation :- a user gives a String (it can be incomplete lower or
|
Explanation :- A user gives a string (it can be incomplete lowercase or
|
||||||
partial lower) and then the program would convert it into a
|
partially in lowercase) and then the program converts it into a
|
||||||
complete(all characters in upper case) upper case string. The
|
completely (all characters in uppercase) uppercase string. The
|
||||||
logic we have used in the following program is: All the lower case
|
logic we have used in the following program is: All the lowercase
|
||||||
characters (a-z) has ASCII value ranging from 97 to 122 and their
|
characters (a-z) has [ASCII](https://en.wikipedia.org/wiki/ASCII) value ranging from 97 to 122 and their
|
||||||
corresponding upper case characters (A-Z) have ASCII values 32
|
corresponding uppercase characters (A-Z) have ASCII values 32
|
||||||
lesser than them. For example ‘a‘ has an ASCII value of 97
|
lesser than them. For example ‘a‘ has an ASCII value of 97
|
||||||
and ‘A‘ has an ASCII value of 65 (97 - 32). The same applies to other
|
and ‘A‘ has an ASCII value of 65 (97 - 32). The same applies to other
|
||||||
characters.
|
characters.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UpperCaseConversion takes any case-style string and converts it to the upper case-style string.
|
* UpperCaseConversion takes any case-style string and converts it to the uppercase-style string.
|
||||||
* @param {String} inputString any case style string
|
* @param {string} inputString Any case style string
|
||||||
* @returns {String} upper case string
|
* @returns {string} Uppercase string
|
||||||
*/
|
*/
|
||||||
const UpperCaseConversion = (inputString) => {
|
const UpperCaseConversion = (inputString) => {
|
||||||
// Take a string and split it into characters.
|
// Take a string and split it into characters.
|
||||||
const newString = inputString.split('').map(char => {
|
const newString = inputString.split('').map(char => {
|
||||||
// Get a character code by the use charCodeAt method.
|
// Get a character code by the use charCodeAt method.
|
||||||
const presentCharCode = char.charCodeAt()
|
const presentCharCode = char.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 lowercase so convert it.
|
||||||
if (presentCharCode >= 97 && presentCharCode <= 122) {
|
if (presentCharCode >= 97 && presentCharCode <= 122) {
|
||||||
// Convert the case by use of the above explanation.
|
// Convert the case by use of the above explanation.
|
||||||
return String.fromCharCode(presentCharCode - 32)
|
return String.fromCharCode(presentCharCode - 32)
|
||||||
|
Reference in New Issue
Block a user