Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions String/Lower.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ const lower = (str) => {
throw new TypeError('Invalid Input Type')
}

return str
.replace(/[A-Z]/g, (_, indexOfUpperChar) => {
const asciiCode = str.charCodeAt(indexOfUpperChar)

return String.fromCharCode(asciiCode + 32)
})
return str.replace(
/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt() + 32)
)
}

export { lower }
export default lower
9 changes: 2 additions & 7 deletions String/Upper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ const upper = (str) => {
}

return str.replace(
/[a-z]/g,
(_, indexOfLowerChar) => {
const asciiCode = str.charCodeAt(indexOfLowerChar)

return String.fromCharCode(asciiCode - 32)
}
/[a-z]/g, (char) => String.fromCharCode(char.charCodeAt() - 32)
)
}

export { upper }
export default upper
2 changes: 1 addition & 1 deletion String/test/Lower.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lower } from '../Lower'
import lower from '../Lower'

describe('Testing the Lower function', () => {
it('Test 1: Check by invalid type', () => {
Expand Down
4 changes: 2 additions & 2 deletions String/test/Upper.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { upper } from '../Upper'
import upper from '../Upper'

describe('Upper', () => {
describe('Testing the Upper function', () => {
it('return uppercase strings', () => {
expect(upper('hello')).toBe('HELLO')
expect(upper('WORLD')).toBe('WORLD')
Expand Down