Skip to content

Commit 86ed0d8

Browse files
committed
fix code style using standardjs
1 parent fbd3442 commit 86ed0d8

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

String/CheckWordOccurrence.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/**
2-
* Check and count occurrence of each word in a string
3-
* Inputs a String eg. Madonna and Boolean
4-
*/
2+
* Check and count occurrence of each word in a string
3+
* Inputs a String eg. Madonna and Boolean
4+
**/
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+
const 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+
}
21+
}
2122

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

String/CheckWordOcurrence.test.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
import { checkWordOccurrence } from './CheckWordOccurrence';
1+
import { checkWordOccurrence } from './CheckWordOccurrence'
22
describe('checkWordOccurrence', () => {
33
it('expects throw on insert wrong string', () => {
4-
const value = 123;
5-
expect(() => checkWordOccurrence(value)).toThrow();
6-
});
4+
const value = 123
5+
expect(() => checkWordOccurrence(value)).toThrow()
6+
})
77
it('expect throw on insert wrong param for case sensitive', () => {
8-
const value = 'hello';
9-
expect(() => checkWordOccurrence(value, value)).toThrow();
10-
});
8+
const value = 'hello'
9+
expect(() => checkWordOccurrence(value, value)).toThrow()
10+
})
1111
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);
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)
1818
expectObjectKeys.forEach(key => {
19-
expect(expectResult[key]).toBe(charsOccurrences[key]);
20-
});
21-
});
19+
expect(expectResult[key]).toBe(charsOccurrences[key])
20+
})
21+
})
2222
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);
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)
2929
expectObjectKeys.forEach(key => {
30-
expect(expectResult[key]).toBe(charsOccurrences[key]);
31-
});
32-
33-
});
34-
});
30+
expect(expectResult[key]).toBe(charsOccurrences[key])
31+
})
32+
})
33+
})

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"node-fetch": "2.6.1"
1717
},
1818
"standard": {
19-
"env": [ "jest" ]
19+
"env": [
20+
"jest"
21+
]
2022
},
2123
"devDependencies": {
2224
"babel-jest": "^26.3.0",

0 commit comments

Comments
 (0)