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 27ae62e

Browse files
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‎

Lines changed: 4 additions & 7 deletions
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‎

Lines changed: 2 additions & 7 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 2 additions & 2 deletions
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)

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