Partition

intermediate5 of 10

Learn about partition in fp-ts array

Code Editor

05-partition.exercise.ts

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

Test Results

Requirements

describe('Array partition operations', () => {
  it('partitions users by age', () => {
    const users = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 15 },
      { name: 'Charlie', age: 30 },
      { name: 'David', age: 17 },
    ]
    const result = partitionByAge(users)
    expect(result.left).toEqual([
      { name: 'Bob', age: 15 },
      { name: 'David', age: 17 },
    ])
    expect(result.right).toEqual([
      { name: 'Alice', age: 25 },
      { name: 'Charlie', age: 30 },
    ])
  })

  it('partitions numbers into odd and even', () => {
    const result = partitionNumbers([1, 2, 3, 4, 5, 6])
    expect(result.left).toEqual([1, 3, 5])
    expect(result.right).toEqual([2, 4, 6])
  })
})
🧪

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