Sort

intermediate4 of 6

Learn about sort in fp-ts nonemptyarray

Code Editor

04-sort.exercise.ts

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

Test Results

Requirements

describe('NonEmptyArray sort', () => {
  it('sorts numbers', () => {
    const arr: NEA.NonEmptyArray<number> = [5, 2, 8, 1, 9]
    const result = sortNumbers(arr)
    expect(result).toEqual([1, 2, 5, 8, 9])
  })

  it('sorts strings', () => {
    const arr: NEA.NonEmptyArray<string> = ['zebra', 'apple', 'mango']
    const result = sortStrings(arr)
    expect(result).toEqual(['apple', 'mango', 'zebra'])
  })

  it('preserves non-emptiness after sort', () => {
    const arr = NEA.of(42)
    const result = sortNumbers(arr)
    expect(result.length).toBeGreaterThan(0)
  })
})
🧪

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