Skip to content

Commit fbd3442

Browse files
committed
fix ident file
1 parent dd40c13 commit fbd3442

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

String/CheckWordOccurrence.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
*/
55

66
const checkWordOccurrence = (str, isCaseSensitive = false) => {
7-
if (typeof str != 'string') {
8-
throw new TypeError('The first param should be a string');
9-
}
10-
if (typeof isCaseSensitive != 'boolean') {
11-
throw new TypeError('The second param should be a boolean')
12-
}
7+
if (typeof str != 'string') {
8+
throw new TypeError('The first param should be a string');
9+
}
10+
if (typeof isCaseSensitive != 'boolean') {
11+
throw new TypeError('The second param should be a boolean')
12+
}
1313

14-
let result = {}
15-
if (str.length > 0) {
16-
for (let i = 0; i < str.length; i++) {
17-
const word = isCaseSensitive ? str[i] : str[i].toUpperCase()
18-
if(/\s/.test(word)) continue;
19-
result[word] = (!result[word]) ? 1 : result[word] + 1
20-
}
14+
let result = {}
15+
if (str.length > 0) {
16+
for (let i = 0; i < str.length; i++) {
17+
const word = isCaseSensitive ? str[i] : str[i].toUpperCase()
18+
if (/\s/.test(word)) continue;
19+
result[word] = (!result[word]) ? 1 : result[word] + 1
20+
}
2121

22-
}
23-
return result;
22+
}
23+
return result;
2424
}
2525
export { checkWordOccurrence }

String/CheckWordOcurrence.test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import {checkWordOccurrence} from './CheckWordOccurrence';
1+
import { checkWordOccurrence } from './CheckWordOccurrence';
22
describe('checkWordOccurrence', () => {
3-
it('expects throw on insert wrong string', () => {
4-
const value = 123;
5-
expect(() => checkWordOccurrence(value)).toThrow();
3+
it('expects throw on insert wrong string', () => {
4+
const value = 123;
5+
expect(() => checkWordOccurrence(value)).toThrow();
6+
});
7+
it('expect throw on insert wrong param for case sensitive', () => {
8+
const value = 'hello';
9+
expect(() => checkWordOccurrence(value, value)).toThrow();
10+
});
11+
it('check occurrence with case sensitive', () => {
12+
const stringToTest = "A Mad World";
13+
const charsOccurrences = checkWordOccurrence(stringToTest, true);
14+
const expectResult = { A: 1, M: 1, a: 1, d: 2, W: 1, l: 1, o: 1, r: 1 };
15+
const occurrencesObjectKeys = Object.keys(charsOccurrences);
16+
const expectObjectKeys = Object.keys(expectResult);
17+
expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length);
18+
expectObjectKeys.forEach(key => {
19+
expect(expectResult[key]).toBe(charsOccurrences[key]);
620
});
7-
it('expect throw on insert wrong param for case sensitive', () => {
8-
const value = 'hello';
9-
expect(() => checkWordOccurrence(value, value)).toThrow();
21+
});
22+
it('check occurrence with case insensitive', () => {
23+
const stringToTest = "A Mad World";
24+
const charsOccurrences = checkWordOccurrence(stringToTest, false);
25+
const expectResult = { A: 2, D: 2, L: 1, M: 1, O: 1, R: 1, W: 1 };
26+
const occurrencesObjectKeys = Object.keys(charsOccurrences);
27+
const expectObjectKeys = Object.keys(expectResult);
28+
expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length);
29+
expectObjectKeys.forEach(key => {
30+
expect(expectResult[key]).toBe(charsOccurrences[key]);
1031
});
11-
it('check occurrence with case sensitive', () => {
12-
const stringToTest = "A Mad World";
13-
const charsOccurrences = checkWordOccurrence(stringToTest, true);
14-
const expectResult = {A: 1, M: 1, a: 1, d: 2, W: 1, l: 1, o: 1, r: 1};
15-
const occurrencesObjectKeys = Object.keys(charsOccurrences);
16-
const expectObjectKeys = Object.keys(expectResult);
17-
expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length);
18-
expectObjectKeys.forEach(key => {
19-
expect(expectResult[key]).toBe(charsOccurrences[key]);
20-
});
21-
});
22-
it('check occurrence with case insensitive', () => {
23-
const stringToTest = "A Mad World";
24-
const charsOccurrences = checkWordOccurrence(stringToTest, false);
25-
const expectResult = {A: 2, D: 2, L: 1, M: 1, O: 1, R: 1, W: 1};
26-
const occurrencesObjectKeys = Object.keys(charsOccurrences);
27-
const expectObjectKeys = Object.keys(expectResult);
28-
expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length);
29-
expectObjectKeys.forEach(key => {
30-
expect(expectResult[key]).toBe(charsOccurrences[key]);
31-
});
3232

33-
});
33+
});
3434
});

0 commit comments

Comments
 (0)