-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatched.js
38 lines (32 loc) · 1009 Bytes
/
matched.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const numbers = [45, 65, 23, 98, 19];
for (let i = 0; i < numbers.length; i++){
const number = numbers[i];
console.log(number);
}
for (const number of numbers){
console.log(number);
}
const products = [
{id: 1, name: 'xiami phone one night', price: 19000},
{id: 2, name: 'iphone', price: 19000},
{id: 3, name: 'mac book air', price: 19000},
{id: 4, name: 'lenovo yoga laptop 2025', price: 19000},
{id: 5, name: 'Dell inspiron laptop', price: 19000},
{id: 6, name: 'Samsung phone note 7', price: 19000},
{id: 7, name: 'nokia old age phone gone', price: 19000},
{id: 8, name: 'phone one', price: 19000},
{id: 9, name: 'M1 chip not cheap LapTOP', price: 19000},
];
for (const product of products){
console.log(product);
}
function matchedProducts (products, search){
const matched = [];
for (const product of products){
if(product.name.toLowerCase().includes(search.toLowerCase())){
matched.push(product);
}
}
}
const result = matchedProducts(products, 'phone');
console.log(result);