Files
JavaScript/Conversions/UpperCaseConversion.js
Roland Hummel 86d333ee94 feat: Test running overhaul, switch to Prettier & reformat everything (#1407)
* chore: Switch to Node 20 + Vitest

* chore: migrate to vitest mock functions

* chore: code style (switch to prettier)

* test: re-enable long-running test

Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime!

see #1193

* chore: code style

* chore: fix failing tests

* Updated Documentation in README.md

* Update contribution guidelines to state usage of Prettier

* fix: set prettier printWidth back to 80

* chore: apply updated code style automatically

* fix: set prettier line endings to lf again

* chore: apply updated code style automatically

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
2023-10-04 02:38:19 +05:30

36 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Explanation :- A user gives a string (it can be incomplete lowercase or
partially in lowercase) and then the program converts it into a
completely (all characters in uppercase) uppercase string. The
logic we have used in the following program is: All the lowercase
characters (a-z) has [ASCII](https://en.wikipedia.org/wiki/ASCII) value ranging from 97 to 122 and their
corresponding uppercase characters (A-Z) have ASCII values 32
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
characters.
*/
/**
* upperCaseConversion takes any case-style string and converts it to the uppercase-style string.
* @param {string} inputString Any case style string
* @returns {string} Uppercase string
*/
const upperCaseConversion = (inputString) => {
// Take a string and split it into characters.
const newString = inputString.split('').map((char) => {
// Get a character code by the use charCodeAt method.
const presentCharCode = char.charCodeAt()
// If the character code lies between 97 to 122, it means they are in the lowercase so convert it.
if (presentCharCode >= 97 && presentCharCode <= 122) {
// Convert the case by use of the above explanation.
return String.fromCharCode(presentCharCode - 32)
}
// Else return the characters without any modification.
return char
})
// After modification, with the help of the join method, join all the characters and return them.
return newString.join('')
}
export { upperCaseConversion }