Pipeline

advanced10 of 10

Learn about pipeline in fp-ts array

Code Editor

10-pipeline.exercise.ts

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

Test Results

Requirements

describe('Array real-world pipeline', () => {
  it('gets affordable electronics sorted by price', () => {
    const products: Product[] = [
      { id: 1, name: 'Laptop', price: 999, category: 'Electronics', inStock: true },
      { id: 2, name: 'Mouse', price: 25, category: 'Electronics', inStock: true },
      { id: 3, name: 'Desk', price: 300, category: 'Furniture', inStock: true },
      { id: 4, name: 'Keyboard', price: 75, category: 'Electronics', inStock: true },
      { id: 5, name: 'Monitor', price: 400, category: 'Electronics', inStock: false },
      { id: 6, name: 'Headphones', price: 150, category: 'Electronics', inStock: true },
    ]
    const result = getAffordableElectronics(products, 200)
    expect(result).toEqual(['Mouse', 'Keyboard', 'Headphones'])
  })

  it('calculates total revenue from multiple orders', () => {
    const orders = [
      { items: [{ price: 10, quantity: 2 }, { price: 5, quantity: 3 }] },
      { items: [{ price: 20, quantity: 1 }] },
      { items: [{ price: 15, quantity: 2 }, { price: 8, quantity: 4 }] },
    ]
    const result = calculateTotalRevenue(orders)
    // (10*2 + 5*3) + (20*1) + (15*2 + 8*4) = (20 + 15) + 20 + (30 + 32) = 35 + 20 + 62 = 117
    expect(result).toBe(117)
  })
})
🧪

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