mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
merge: reduce upper & lower & add export default (#960)
This commit is contained in:
@ -12,12 +12,9 @@ const lower = (str) => {
|
|||||||
throw new TypeError('Invalid Input Type')
|
throw new TypeError('Invalid Input Type')
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str.replace(
|
||||||
.replace(/[A-Z]/g, (_, indexOfUpperChar) => {
|
/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt() + 32)
|
||||||
const asciiCode = str.charCodeAt(indexOfUpperChar)
|
)
|
||||||
|
|
||||||
return String.fromCharCode(asciiCode + 32)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { lower }
|
export default lower
|
||||||
|
@ -12,13 +12,8 @@ const upper = (str) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return str.replace(
|
return str.replace(
|
||||||
/[a-z]/g,
|
/[a-z]/g, (char) => String.fromCharCode(char.charCodeAt() - 32)
|
||||||
(_, indexOfLowerChar) => {
|
|
||||||
const asciiCode = str.charCodeAt(indexOfLowerChar)
|
|
||||||
|
|
||||||
return String.fromCharCode(asciiCode - 32)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { upper }
|
export default upper
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { lower } from '../Lower'
|
import lower from '../Lower'
|
||||||
|
|
||||||
describe('Testing the Lower function', () => {
|
describe('Testing the Lower function', () => {
|
||||||
it('Test 1: Check by invalid type', () => {
|
it('Test 1: Check by invalid type', () => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { upper } from '../Upper'
|
import upper from '../Upper'
|
||||||
|
|
||||||
describe('Upper', () => {
|
describe('Testing the Upper function', () => {
|
||||||
it('return uppercase strings', () => {
|
it('return uppercase strings', () => {
|
||||||
expect(upper('hello')).toBe('HELLO')
|
expect(upper('hello')).toBe('HELLO')
|
||||||
expect(upper('WORLD')).toBe('WORLD')
|
expect(upper('WORLD')).toBe('WORLD')
|
||||||
|
Reference in New Issue
Block a user