From 31be2b34f016af227c964cc6ddd3510ebc6fc6c1 Mon Sep 17 00:00:00 2001 From: Fahim Faisaal Date: Mon, 28 Mar 2022 11:58:55 +0600 Subject: [PATCH] refactor: reduce upper & lower & add export default --- String/Lower.js | 11 ++++------- String/Upper.js | 9 ++------- String/test/Lower.test.js | 2 +- String/test/Upper.test.js | 4 ++-- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/String/Lower.js b/String/Lower.js index 73d61878c0..02b79ffc89 100644 --- a/String/Lower.js +++ b/String/Lower.js @@ -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 diff --git a/String/Upper.js b/String/Upper.js index 3ec1611e76..90fc3938cb 100644 --- a/String/Upper.js +++ b/String/Upper.js @@ -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 diff --git a/String/test/Lower.test.js b/String/test/Lower.test.js index 4a211c38aa..01fbd7c2ba 100644 --- a/String/test/Lower.test.js +++ b/String/test/Lower.test.js @@ -1,4 +1,4 @@ -import { lower } from '../Lower' +import lower from '../Lower' describe('Testing the Lower function', () => { it('Test 1: Check by invalid type', () => { diff --git a/String/test/Upper.test.js b/String/test/Upper.test.js index 81d605220e..1cc227689c 100644 --- a/String/test/Upper.test.js +++ b/String/test/Upper.test.js @@ -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') 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