Assigned to: Groups 3 & 4
Estimated time: 20 minutes
Difficulty: ββ Medium
The getStrongestPokemon function has a bug - when multiple Pokemon have the SAME attack stat, it only returns the first one. We need to return ALL tied Pokemon.
- π§ͺ Write a test that DEMONSTRATES the bug
- π Fix the function to return an ARRAY of Pokemon (even if just one)
- β Make sure all tests pass
- π Update existing test to expect an array
test('should return all Pokemon when tied for highest attack', () => {
const tiedPokemon = [
{ name: "Charizard", attack: 84 },
{ name: "Mewtwo", attack: 84 }, // Same attack!
{ name: "Pikachu", attack: 55 }
];
const result = getStrongestPokemon(tiedPokemon);
// TODO: What should we expect?
// Should be an array with BOTH Charizard and Mewtwo
expect(result).toHaveLength(2);
expect(result[0].name).toBe('Charizard');
expect(result[1].name).toBe('Mewtwo');
});Hints:
- Change return type to ALWAYS return an array
- Find the highest attack value first
- Then filter all Pokemon that match that value
git checkout -b ticket-2-fix-tie-bug
git commit -m "test: add failing test for tied attack stats"
git commit -m "fix: return array of all strongest Pokemon"
git commit -m "test: update existing test to expect array"
git push origin ticket-2-fix-tie-bug- Test demonstrates the bug (fails initially)
- Function returns array of ALL strongest Pokemon
- All tests pass
- Old test updated to work with array return