Group

intermediate5 of 6

Learn about group in fp-ts nonemptyarray

Code Editor

05-group.exercise.ts

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

Test Results

Requirements

describe('NonEmptyArray grouping', () => {
  it('groups consecutive equal numbers', () => {
    const arr: NEA.NonEmptyArray<number> = [1, 1, 2, 2, 2, 3, 1]
    const result = groupConsecutive(arr)
    expect(result).toEqual([[1, 1], [2, 2, 2], [3], [1]])
  })

  it('groups by parity', () => {
    const arr: NEA.NonEmptyArray<number> = [1, 3, 5, 2, 4, 7, 9]
    const result = groupByParity(arr)
    expect(result).toEqual([[1, 3, 5], [2, 4], [7, 9]])
  })

  it('single element creates single group', () => {
    const arr = NEA.of(42)
    const result = groupConsecutive(arr)
    expect(result).toEqual([[42]])
  })
})
🧪

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