Product Search and Filter
Build search and filter helpers for a product list.
5 upvotes
10 upvotes
Product Search and Filter
You are building search helpers for a small product list. Some helpers should return multiple products, and one helper should return a single product.
Write these functions:
filterByCategory(products, category)should return products in the matching category.filterByMaxPrice(products, maxPrice)should return products at or below the max price.getInStockProducts(products)should return products whereinStockistrue.findProductById(products, productId)should return one matching product orundefined.searchProducts(products, searchText)should return products whose name includes the search text, ignoring casing.
Sample checks:
Expected output:
Search should be case-insensitive. The original products array should not be changed.
Solution
Solution:
