Compact
Learn about compact in fp-ts array
Code Editor
09-compact.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Array compact operations', () => {
it('removes None values and extracts Some values', () => {
const numbers = [O.some(1), O.none, O.some(2), O.none, O.some(3)]
const result = getValidNumbers(numbers)
expect(result).toEqual([1, 2, 3])
})
it('returns empty array when all None', () => {
const numbers = [O.none, O.none, O.none]
const result = getValidNumbers(numbers)
expect(result).toEqual([])
})
it('safely divides numbers, skipping zeros', () => {
const result = safeDivide([2, 0, 5, 0, 10])
expect(result).toEqual([50, 20, 10])
})
})🧪
Ready to Test?
Click "Run Tests" to see how your code performs
Quick Tips
•Read the TODO comments in the code
•Use Reset to restore original code
•Check Solution if stuck
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