StephenGrider/AlgoCasts

False positive on maxChar exercise

Opened this issue · 1 comments

Hello! I was writing a solution for your maxChar problem and I passed all your tests. However, when I ran the solution against string 'cacacbb', it returned 'b' instead of 'c'. Since my faulty function has passed all the original tests, I assume other students could have the same issue, so I added:

expect(maxChar('cacacbb')).toEqual('c');

to AlgoCasts/exercises/maxchar/test.js
Here is the link to my pull request: #3

Here is my faulty function that passed the original tests:
function maxChar(str) {
var letter;
var count = 0;
str.split('').forEach((item, index) => {
if(letter === undefined || item === letter) {
letter = item;
count++;
} else {
if(count === 1){
letter = item
}
}
});
return letter;
}

This was a good opportunity to dig into and edit the tests :).

I added the following:
expect(maxChar('Hello World')).toEqual('l');