Reduce

beginner3 of 10

Learn about reduce in fp-ts array

Code Editor

03-reduce.exercise.ts

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

Test Results

Requirements

describe('Array reduce operations', () => {
  it('sums all numbers', () => {
    const result = sumNumbers([1, 2, 3, 4, 5])
    expect(result).toBe(15)
  })

  it('returns 0 for empty array', () => {
    const result = sumNumbers([])
    expect(result).toBe(0)
  })

  it('concatenates strings with spaces', () => {
    const result = concatenateStrings(['Hello', 'functional', 'world'])
    expect(result).toBe('Hello functional world')
  })

  it('handles single string', () => {
    const result = concatenateStrings(['Hello'])
    expect(result).toBe('Hello')
  })
})
🧪

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