Skip to content

Instantly share code, notes, and snippets.

@manavm1990
Created October 21, 2025 00:02
Show Gist options
  • Select an option

  • Save manavm1990/39f38c8b2a11677c19cb973b7d43d481 to your computer and use it in GitHub Desktop.

Select an option

Save manavm1990/39f38c8b2a11677c19cb973b7d43d481 to your computer and use it in GitHub Desktop.

Ticket #2: Fix the Tie Bug

Assigned to: Groups 3 & 4
Estimated time: 20 minutes
Difficulty: ⭐⭐ Medium

What You're Doing

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.

Tasks

  1. πŸ§ͺ Write a test that DEMONSTRATES the bug
  2. πŸ› Fix the function to return an ARRAY of Pokemon (even if just one)
  3. βœ… Make sure all tests pass
  4. πŸ“ Update existing test to expect an array

Step 1: Write Test That Shows Bug

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');
});

Step 2: Fix the Function

Hints:

  • Change return type to ALWAYS return an array
  • Find the highest attack value first
  • Then filter all Pokemon that match that value

Git Workflow

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

Success Criteria

  • Test demonstrates the bug (fails initially)
  • Function returns array of ALL strongest Pokemon
  • All tests pass
  • Old test updated to work with array return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment