Contramap

beginner2 of 6

Learn about contramap in fp-ts ord

Code Editor

02-contramap.exercise.ts

💻
Loading editor...
Preparing Monaco Editor with TypeScript support

Test Results

Requirements

describe('Ord contramap', () => {
  it('sorts by age', () => {
    const people: Person[] = [
      { name: 'Alice', age: 30 },
      { name: 'Bob', age: 25 },
      { name: 'Charlie', age: 35 },
    ]
    const sorted = [...people].sort(byAge.compare)
    expect(sorted[0].name).toBe('Bob')
    expect(sorted[2].name).toBe('Charlie')
  })

  it('sorts by name length', () => {
    const people: Person[] = [
      { name: 'Alice', age: 30 },
      { name: 'Bob', age: 25 },
      { name: 'Charlie', age: 35 },
    ]
    const sorted = [...people].sort(byNameLength.compare)
    expect(sorted[0].name).toBe('Bob')
    expect(sorted[2].name).toBe('Charlie')
  })
})
🧪

Ready to Test?

Click "Run Tests" to see how your code performs

Pro Tips

💡 Stuck? Here's what to try:

  • • Read the comments in the code carefully
  • • Run tests frequently to get feedback
  • • Check the fp-ts documentation
  • • Use the solution if you need help

🚀 Learning Approach:

  • • Focus on understanding, not just solving
  • • Experiment with different approaches
  • • Think about real-world applications
  • • Build on previous exercises