Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 43515a6

Browse files
merge: Add Upper (#862)
1 parent 4c27e15 commit 43515a6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎String/Upper.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @function upper
3+
* @description Will convert the entire string to uppercase letters.
4+
* @param {String} url - The input URL string
5+
* @return {String} Uppercase string
6+
* @example upper("hello") => HELLO
7+
* @example upper("He_llo") => HE_LLO
8+
*/
9+
10+
const upper = (str) => {
11+
if (typeof str !== 'string') {
12+
throw new TypeError('Invalid Input Type')
13+
}
14+
15+
let upperString = ''
16+
17+
for (const char of str) {
18+
let asciiCode = char.charCodeAt(0)
19+
if (asciiCode >= 97 && asciiCode <= 122) {
20+
asciiCode -= 32
21+
}
22+
upperString += String.fromCharCode(asciiCode)
23+
}
24+
25+
return upperString
26+
}
27+
28+
export { upper }

‎String/test/Upper.test.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { upper } from '../Upper'
2+
3+
describe('Upper', () => {
4+
it('return uppercase strings', () => {
5+
expect(upper('hello')).toBe('HELLO')
6+
expect(upper('WORLD')).toBe('WORLD')
7+
expect(upper('hello_WORLD')).toBe('HELLO_WORLD')
8+
})
9+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /