Skip to content

Commit ca4e3cf

Browse files
matthewmorganrchavarria
authored andcommitted
Update tests and example to be case-agnostic
1 parent 3aa99ce commit ca4e3cf

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎exercises/word-count/example.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Words.prototype.count = function (input) {
77
var words = input.match(/\S+/g);
88

99
words.forEach(function (word) {
10-
counts[word] = counts.hasOwnProperty(word) ? counts[word] + 1 : 1;
10+
var lcWord = word.toLowerCase();
11+
counts[lcWord] = counts.hasOwnProperty(lcWord) ? counts[lcWord] + 1 : 1;
1112
});
1213

1314
return counts;

‎exercises/word-count/word-count.spec.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ describe('count()', function() {
2929
});
3030

3131
xit('respects case', function() {
32-
var expectedCounts = { go: 1, Go:1, GO:1 };
32+
var expectedCounts = { go: 3 };
3333
expect(words.count('go Go GO')).toEqual(expectedCounts);
3434
});
3535

3636
xit('counts properly international characters', function() {
37-
var expectedCounts = { '¡Hola!': 1, '¿Qué': 1, 'tal?': 1, 'Привет!': 1 };
37+
var expectedCounts = { '¡hola!': 1, '¿qué': 1, 'tal?': 1, 'привет!': 1 };
3838
expect(words.count('¡Hola! ¿Qué tal? Привет!')).toEqual(expectedCounts);
3939
});
4040

@@ -54,12 +54,12 @@ describe('count()', function() {
5454
});
5555

5656
xit('does not count leading or trailing whitespace', function() {
57-
var expectedCounts = { Introductory: 1, Course: 1 };
57+
var expectedCounts = { introductory: 1, course: 1 };
5858
expect(words.count('\t\tIntroductory Course ')).toEqual(expectedCounts);
5959
});
6060

6161
xit('handles properties that exist on Object’s prototype', function() {
62-
var expectedCounts = { reserved: 1, words : 1, like :1, prototype: 1, and : 1, toString: 1, 'ok?': 1};
62+
var expectedCounts = { reserved: 1, words : 1, like :1, prototype: 1, and : 1, tostring: 1, 'ok?': 1};
6363
expect(words.count('reserved words like prototype and toString ok?')).toEqual(expectedCounts);
6464
});
6565
});

0 commit comments

Comments
 (0)