From fbd3442cf0c5cc69f259b99cea4397721fdf6d2e Mon Sep 17 00:00:00 2001 From: Carlos Carvalho Date: Mon, 5 Oct 2020 23:52:21 -0300 Subject: [PATCH] fix ident file --- String/CheckWordOccurrence.js | 30 ++++++++-------- String/CheckWordOcurrence.test.js | 58 +++++++++++++++---------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/String/CheckWordOccurrence.js b/String/CheckWordOccurrence.js index d17b2a0cf..f31df400b 100644 --- a/String/CheckWordOccurrence.js +++ b/String/CheckWordOccurrence.js @@ -4,22 +4,22 @@ */ const checkWordOccurrence = (str, isCaseSensitive = false) => { - if (typeof str != 'string') { - throw new TypeError('The first param should be a string'); - } - if (typeof isCaseSensitive != 'boolean') { - throw new TypeError('The second param should be a boolean') - } + if (typeof str != 'string') { + throw new TypeError('The first param should be a string'); + } + if (typeof isCaseSensitive != 'boolean') { + throw new TypeError('The second param should be a boolean') + } - let result = {} - if (str.length > 0) { - for (let i = 0; i < str.length; i++) { - const word = isCaseSensitive ? str[i] : str[i].toUpperCase() - if(/\s/.test(word)) continue; - result[word] = (!result[word]) ? 1 : result[word] + 1 - } + let result = {} + if (str.length > 0) { + for (let i = 0; i < str.length; i++) { + const word = isCaseSensitive ? str[i] : str[i].toUpperCase() + if (/\s/.test(word)) continue; + result[word] = (!result[word]) ? 1 : result[word] + 1 + } - } - return result; + } + return result; } export { checkWordOccurrence } \ No newline at end of file diff --git a/String/CheckWordOcurrence.test.js b/String/CheckWordOcurrence.test.js index 0e57ad655..cd5673885 100644 --- a/String/CheckWordOcurrence.test.js +++ b/String/CheckWordOcurrence.test.js @@ -1,34 +1,34 @@ -import {checkWordOccurrence} from './CheckWordOccurrence'; +import { checkWordOccurrence } from './CheckWordOccurrence'; describe('checkWordOccurrence', () => { - it('expects throw on insert wrong string', () => { - const value = 123; - expect(() => checkWordOccurrence(value)).toThrow(); + it('expects throw on insert wrong string', () => { + const value = 123; + expect(() => checkWordOccurrence(value)).toThrow(); + }); + it('expect throw on insert wrong param for case sensitive', () => { + const value = 'hello'; + expect(() => checkWordOccurrence(value, value)).toThrow(); + }); + it('check occurrence with case sensitive', () => { + const stringToTest = "A Mad World"; + const charsOccurrences = checkWordOccurrence(stringToTest, true); + const expectResult = { A: 1, M: 1, a: 1, d: 2, W: 1, l: 1, o: 1, r: 1 }; + const occurrencesObjectKeys = Object.keys(charsOccurrences); + const expectObjectKeys = Object.keys(expectResult); + expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length); + expectObjectKeys.forEach(key => { + expect(expectResult[key]).toBe(charsOccurrences[key]); }); - it('expect throw on insert wrong param for case sensitive', () => { - const value = 'hello'; - expect(() => checkWordOccurrence(value, value)).toThrow(); + }); + it('check occurrence with case insensitive', () => { + const stringToTest = "A Mad World"; + const charsOccurrences = checkWordOccurrence(stringToTest, false); + const expectResult = { A: 2, D: 2, L: 1, M: 1, O: 1, R: 1, W: 1 }; + const occurrencesObjectKeys = Object.keys(charsOccurrences); + const expectObjectKeys = Object.keys(expectResult); + expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length); + expectObjectKeys.forEach(key => { + expect(expectResult[key]).toBe(charsOccurrences[key]); }); - it('check occurrence with case sensitive', () => { - const stringToTest = "A Mad World"; - const charsOccurrences = checkWordOccurrence(stringToTest, true); - const expectResult = {A: 1, M: 1, a: 1, d: 2, W: 1, l: 1, o: 1, r: 1}; - const occurrencesObjectKeys = Object.keys(charsOccurrences); - const expectObjectKeys = Object.keys(expectResult); - expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length); - expectObjectKeys.forEach(key => { - expect(expectResult[key]).toBe(charsOccurrences[key]); - }); - }); - it('check occurrence with case insensitive', () => { - const stringToTest = "A Mad World"; - const charsOccurrences = checkWordOccurrence(stringToTest, false); - const expectResult = {A: 2, D: 2, L: 1, M: 1, O: 1, R: 1, W: 1}; - const occurrencesObjectKeys = Object.keys(charsOccurrences); - const expectObjectKeys = Object.keys(expectResult); - expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length); - expectObjectKeys.forEach(key => { - expect(expectResult[key]).toBe(charsOccurrences[key]); - }); - }); + }); }); \ No newline at end of file