Skip to content

Commit 27ae62e

Browse files
authored
merge: reduce upper & lower & add export default (TheAlgorithms#960)
1 parent 3b9af46 commit 27ae62e

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

String/Lower.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ const lower = (str) => {
1212
throw new TypeError('Invalid Input Type')
1313
}
1414

15-
return str
16-
.replace(/[A-Z]/g, (_, indexOfUpperChar) => {
17-
const asciiCode = str.charCodeAt(indexOfUpperChar)
18-
19-
return String.fromCharCode(asciiCode + 32)
20-
})
15+
return str.replace(
16+
/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt() + 32)
17+
)
2118
}
2219

23-
export { lower }
20+
export default lower

String/Upper.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ const upper = (str) => {
1212
}
1313

1414
return str.replace(
15-
/[a-z]/g,
16-
(_, indexOfLowerChar) => {
17-
const asciiCode = str.charCodeAt(indexOfLowerChar)
18-
19-
return String.fromCharCode(asciiCode - 32)
20-
}
15+
/[a-z]/g, (char) => String.fromCharCode(char.charCodeAt() - 32)
2116
)
2217
}
2318

24-
export { upper }
19+
export default upper

String/test/Lower.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lower } from '../Lower'
1+
import lower from '../Lower'
22

33
describe('Testing the Lower function', () => {
44
it('Test 1: Check by invalid type', () => {

String/test/Upper.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { upper } from '../Upper'
1+
import upper from '../Upper'
22

3-
describe('Upper', () => {
3+
describe('Testing the Upper function', () => {
44
it('return uppercase strings', () => {
55
expect(upper('hello')).toBe('HELLO')
66
expect(upper('WORLD')).toBe('WORLD')

0 commit comments

Comments
 (0)