Filter

beginner2 of 8

Learn about filter in fp-ts record

Code Editor

02-filter.exercise.ts

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

Test Results

Requirements

describe('Record filter operations', () => {
  it('filters positive numbers', () => {
    const input = { a: 5, b: -2, c: 10, d: -7, e: 3 }
    const result = filterPositive(input)
    expect(result).toEqual({ a: 5, c: 10, e: 3 })
  })

  it('returns empty record when no matches', () => {
    const input = { a: -1, b: -2 }
    const result = filterPositive(input)
    expect(result).toEqual({})
  })

  it('filters by string length', () => {
    const input = { a: 'hi', b: 'hello', c: 'hey', d: 'goodbye' }
    const result = filterByLength(input, 5)
    expect(result).toEqual({ b: 'hello', d: 'goodbye' })
  })
})
🧪

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