search (criteria) – returns an array containing the product objects that match the criteria argument. The criteria is a single-property object where the key is either 'price' or 'keyword'. When the key is 'price' it returns the products whose price is less than (or equal to) the specified value, e.g.
search({ price: 25.00})
should return products cheaper than €25.01.
When the key is 'keyword' it returns the products with the keyword in their name, e.g.
search({ keyword: ‘sho’ })
should return products with 'sho' in the name (e.g. shoes, shoulder bag).
If the criteria object has neither key then an exception should be thrown with the message 'Bad search'. A simple example of the method invocation might be:
const result = catalogue.search({ keyword: "Widget" })
console.log(result[0].name) // Display name of first product object
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/168417.html
標籤:JavaScript
上一篇:公司面試題,大佬求幫忙
