Find

intermediate4 of 10

Learn about find in fp-ts array

Code Editor

04-find.exercise.ts

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

Test Results

Requirements

describe('Array find operations', () => {
  it('finds first even number', () => {
    const result = findFirstEven([1, 3, 4, 5, 6])
    expect(O.isSome(result)).toBe(true)
    expect(result).toEqual(O.some(4))
  })

  it('returns None when no even number found', () => {
    const result = findFirstEven([1, 3, 5])
    expect(O.isNone(result)).toBe(true)
  })

  it('finds user by name', () => {
    const users = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 35 },
    ]
    const result = findUserByName(users, 'Bob')
    expect(result).toEqual(O.some({ name: 'Bob', age: 30 }))
  })

  it('returns None when user not found', () => {
    const users = [{ name: 'Alice', age: 25 }]
    const result = findUserByName(users, 'Bob')
    expect(O.isNone(result)).toBe(true)
  })
})
🧪

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