-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring-search.js
61 lines (46 loc) · 1.2 KB
/
string-search.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const products =[
'Dell hardcore i29 200GB processor laptop',
'iPhone 1TB camera Phone',
'yellow laptop with black camera',
'1X59 Lenova cammercial yopa laptop',
'purpel color phone with LapTop',
'LG supernova laptop',
'Lava smart phone',
'corei7 laptop',
'Grammin Phone'
]
const search = 'phone';
const output =[];
// indexOf
for(const product of products){
if(product.toLowerCase().indexOf(search.toLowerCase())!=-1){
// output.push(product);
}
}
// console.log(output);
/* for(const product of products){
if(product.toLowerCase().includes(search.toLowerCase())){
output.push(product)
}
}
console.log(output); */
// startsWith
/* for(const product of products){
if(product.toLowerCase().startsWith(search.toLowerCase())){
output.push(product)
}
}
console.log(output); */
/* for(const product of products){
if(product.toLowerCase().endsWith(search.toLowerCase())){
output.push(product)
}
}
console.log(output); */
/* for(const product of products){
// console.log(product);
if(product.toLocaleLowerCase().indexOf(search.toLowerCase()) != -1){
output.push(product)
}
console.log(output);
} */