-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path520_Detect_Capital.js
More file actions
47 lines (40 loc) · 1.33 KB
/
Copy path520_Detect_Capital.js
File metadata and controls
47 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.
We define the usage of capitals in a word to be right when one of the following cases holds:
1. All letters in this word are capitals, like "USA".
2. All letters in this word are not capitals, like "leetcode".
3. Only the first letter in this word is capital, if it has more than one letter, like "Google".
Otherwise, we define that this word doesn 't use capitals in a right way.
*/
const expect = require('expect');
describe('520 Detect Capital', () => {
it('all upper case returns true', () => {
//arrange
const input = 'USA';
const expected = true;
//act
const actual = detectCapitalUse(input);
//assert
expect(actual).toBe(expected);
});
it('all lower case returns true', () => {
//arrange
const input = 'leetcode';
const expected = true;
//act
const actual = detectCapitalUse(input);
//assert
expect(actual).toBe(expected);
});
it('only the first letter is capital returns true', () => {
//arrange
const input = 'Google';
const expected = true;
//act
const actual = detectCapitalUse(input);
//assert
expect(actual).toBe(expected);
});
});
const detectCapitalUse = word => word.toUpperCase() === word || word.slice(1).toLowerCase() === word.slice(1);