-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_maps.js
111 lines (94 loc) · 2.22 KB
/
filter_maps.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const students = [
{
id: 1,
name: "Amit Sharma",
age: 22,
course: "B.Tech CSE",
grade: "A",
city: "Delhi"
},
{
id: 2,
name: "Priya Verma",
age: 22,
course: "B.Sc Mathematics",
grade: "B+",
city: "Mumbai"
},
{
id: 3,
name: "Rahul Singh",
age: 20,
course: "BCA",
grade: "A-",
city: "Bangalore"
},
{
id: 4,
name: "Sneha Patel",
age: 23,
course: "M.Tech AI",
grade: "A+",
city: "Hyderabad"
}
];
//filter returns the value if you use scope({}) musr use return
const Studentinformation = students.filter((key)=> key.city==="Hyderabad")
//console.log(Studentinformation);
//map is also used it also return in true and false formate
//if no operatin is prformed value also remember if you use scope({}) musr use return
const information1=students.map((key)=>key.age===22)
//console.log(information1);
const information2=students.map((key,value)=>key.age+1)
//console.log(information2);
//array.reduce()
const arrray1=[1,2,3,4,5,6];
const initialvalue=0;
const SumWithInitial=arrray1.reduce((value,currentvalue)=> value+currentvalue,initialvalue);
//console.log(SumWithInitial);
const arr2=[1,2,3]
const Totalsum=arr2.reduce((acc,currval)=>
{
//console.log(`acc:- ${acc} and currval:- ${currval}`);
return acc+currval;
},1)
//console.log(Totalsum);
const cart = [
{
id: 1,
name: "Wireless Mouse",
price: 599.99,
quantity: 2,
category: "Electronics"
},
{
id: 2,
name: "Bluetooth Headphones",
price: 1299.50,
quantity: 1,
category: "Electronics"
},
{
id: 3,
name: "T-Shirt",
price: 499.00,
quantity: 3,
category: "Clothing"
},
{
id: 4,
name: "Running Shoes",
price: 2299.99,
quantity: 1,
category: "Footwear"
},
{
id: 5,
name: "Water Bottle",
price: 299.00,
quantity: 2,
category: "Accessories"
}
];
const TotalPrice=cart.reduce((acc,Total)=> acc+Total.price,0);
console.log(TotalPrice);