Filter

beginner2 of 10

Learn about filter in fp-ts array

Code Editor

02-filter.exercise.ts

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

Test Results

Requirements

describe('Array filter operations', () => {
  it('filters even numbers', () => {
    const result = filterEvenNumbers([1, 2, 3, 4, 5, 6])
    expect(result).toEqual([2, 4, 6])
  })

  it('returns empty array when no matches', () => {
    const result = filterEvenNumbers([1, 3, 5])
    expect(result).toEqual([])
  })

  it('filters adult users', () => {
    const users = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 15 },
      { name: 'Charlie', age: 30 },
      { name: 'David', age: 17 },
    ]
    const result = filterAdults(users)
    expect(result).toEqual([
      { name: 'Alice', age: 25 },
      { name: 'Charlie', age: 30 },
    ])
  })
})
🧪

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