From 4a263477671d69d2abf2a5b54b061f28d993d1f5 Mon Sep 17 00:00:00 2001 From: Askar Garifullin Date: Fri, 16 Oct 2020 14:50:14 +0500 Subject: [PATCH 1/2] Added check pangram algorithm --- String/CheckPangram.js | 0 String/test/CheckPangram.test.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 String/CheckPangram.js create mode 100644 String/test/CheckPangram.test.js diff --git a/String/CheckPangram.js b/String/CheckPangram.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/String/test/CheckPangram.test.js b/String/test/CheckPangram.test.js new file mode 100644 index 0000000000..e69de29bb2 From 54198ac3142a0ff781c9b0560c16856a772dc1fa Mon Sep 17 00:00:00 2001 From: garifullin_aa Date: Fri, 16 Oct 2020 15:01:39 +0500 Subject: [PATCH 2/2] Added check pangram algorithm --- String/CheckPangram.js | 22 +++++++++++++++++++++ String/test/CheckPangram.test.js | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/String/CheckPangram.js b/String/CheckPangram.js index e69de29bb2..b95b0c05eb 100644 --- a/String/CheckPangram.js +++ b/String/CheckPangram.js @@ -0,0 +1,22 @@ +/* + Pangram is a sentence that contains all the letters in the alphabet + https://en.wikipedia.org/wiki/Pangram + */ + +const checkPangram = (string) => { + if (typeof string !== 'string') { + throw new TypeError('The given value is not a string') + } + + const frequency = new Set() + + for (const letter of string.toLowerCase()) { + if (letter >= 'a' && letter <= 'z') { + frequency.add(letter) + } + } + + return frequency.size === 26 +} + +export { checkPangram } diff --git a/String/test/CheckPangram.test.js b/String/test/CheckPangram.test.js index e69de29bb2..f062ed44f3 100644 --- a/String/test/CheckPangram.test.js +++ b/String/test/CheckPangram.test.js @@ -0,0 +1,33 @@ +import { checkPangram } from '../CheckPangram' + +describe('checkPangram', () => { + it('"The quick brown fox jumps over the lazy dog" is a pangram', () => { + expect( + checkPangram('The quick brown fox jumps over the lazy dog') + ).toBeTruthy() + }) + + it('"Waltz, bad nymph, for quick jigs vex." is a pangram', () => { + expect(checkPangram('Waltz, bad nymph, for quick jigs vex.')).toBeTruthy() + }) + + it('"Jived fox nymph grabs quick waltz." is a pangram', () => { + expect(checkPangram('Jived fox nymph grabs quick waltz.')).toBeTruthy() + }) + + it('"My name is Unknown" is NOT a pangram', () => { + expect(checkPangram('My name is Unknown')).toBeFalsy() + }) + + it('"The quick brown fox jumps over the la_y dog" is NOT a pangram', () => { + expect( + checkPangram('The quick brown fox jumps over the la_y dog') + ).toBeFalsy() + }) + + it('Throws an error if given param is not a string', () => { + expect(() => { + checkPangram(undefined) + }).toThrow('The given value is not a string') + }) +})