Custom

beginner3 of 4

Learn about custom in fp-ts monoid

Code Editor

03-custom.exercise.ts

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

Test Results

Requirements

describe('Custom Monoids', () => {
  it('finds maximum with MaxMonoid', () => {
    expect(combineMax([3, 7, 2, 9, 1])).toBe(9)
    expect(combineMax([5])).toBe(5)
    expect(combineMax([])).toBe(-Infinity)
  })

  it('flattens arrays with ArrayMonoid', () => {
    const result = flattenArrays([[1, 2], [3, 4], [5]])
    expect(result).toEqual([1, 2, 3, 4, 5])
  })

  it('handles empty nested arrays', () => {
    expect(flattenArrays([])).toEqual([])
    expect(flattenArrays([[], [], []])).toEqual([])
  })
})
🧪

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