AlgoCasts icon indicating copy to clipboard operation
AlgoCasts copied to clipboard

False positive on maxChar exercise

Open vvnsze opened this issue 7 years ago • 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: https://github.com/StephenGrider/AlgoCasts/pull/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; }

vvnsze avatar Nov 20 '17 05:11 vvnsze

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

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

JuiceyDuecy avatar Jul 13 '20 09:07 JuiceyDuecy