Skip to content

reduce upper & lower & add export default #960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2022
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy