Filter

Filter
πŸ‘¨β€πŸ’Ό The filter method creates a new array with only elements that pass a test.
const numbers = [1, 2, 3, 4, 5]
const evens = numbers.filter((n) => n % 2 === 0)
// [2, 4]
The callback returns true to keep the element or false to exclude it.
🐨 Open
index.ts
and use the provided products fixture:
  1. Create electronics: products where category === 'Electronics' (names: Laptop, Headphones, Monitor)
  2. Create affordable: products where price < 100 (names: Toaster, Blender)
  3. Create available: products where inStock === true (length 4)
  4. Create inStockElectronicsUnder500: the names of products that are in stock, in the Electronics category, and have price < 500 β€” expected ['Monitor']
  5. Export electronics, affordable, available, and inStockElectronicsUnder500
πŸ’° filter keeps items where your callback returns true.

Please set the playground first

Loading "Filter"
Loading "Filter"