-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.js
More file actions
143 lines (129 loc) · 4.1 KB
/
Array.js
File metadata and controls
143 lines (129 loc) · 4.1 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//let marks = [87, 85, 67, 89, 94, 99, 78];
/*
console.log(marks)
console.log(marks.length)
console.log(typeof marks)
console.log(marks[0])
console.log(marks[1])
console.log(marks[2])
console.log(marks[3])
console.log(marks[4])
console.log(marks[5])
console.log(marks[6])
console.log(marks[7])
*/
/*
console.log("Using for Loop")
console.log("for Loop Used To Print Elements Of Array")
for(let indx=0;indx<marks.length;indx++){
console.log(marks[indx])
}
console.log("Using for of Loop")
console.log("for of Loop Used To Print Elements Of Array")
for(let element of marks){
console.log(element)
}
let cities=["Bhubaneswar","Cuttack","Gangam","Baripada","Balasore","Bhadrak","Paradeep","Rourkela"]
console.log("Using for of Loop")
console.log("for of Loop Used To Print Elements Of Array")
for(let city of cities){
console.log(city.toUpperCase())
}
for(let city of cities){
console.log(city.toLowerCase())
}
console.log("Using for in Loop")
console.log("for in Loop Used To Print Indices Of Array")
for(let index in marks){
console.log(index)
}
*/
/*
console.log("Finding Average Of Array Elements")
let marksOfWholeStudent=[85,64,97,91,94,88,75]
console.log("The Length Of Array is : ",marksOfWholeStudent.length)
sum=0
for(let i=0;i<marksOfWholeStudent.length;i++){
console.log("Before Iteration : ",sum)
sum+=marksOfWholeStudent[i]
console.log("After Itrration : ",sum)
}
console.log("The Sum Of Marks Of Whole Class is : ",sum)
let average=sum/marksOfWholeStudent.length
console.log("The Average Of Whole Class Marks is : ",average)
*/
/*
let sum = 0;
let marksOfWholeStudent = [85, 64, 97, 91, 94, 88, 75];
for (let element of marksOfWholeStudent) {
sum += element;
}
let average=sum/marksOfWholeStudent.length
console.log("The Average is : ",average)
*/
/*
let newprice
let items=[250,645,300,900,50]
for(let price of items){
console.log(`The Old Price Of The Items is ${price} `)
newprice=price-(price/10)
console.log(`The New Price Of Items After 10% Discount is ${newprice} `)
}
*/
/*
console.log("Push Method in Array")
let Vehicle=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
console.log("The Original Array is : ",Vehicle)
Vehicle.push("Punch.ev","Baleno","Lambo","Chevrelot")
console.log("The Array After Pushing New Element is : ",Vehicle)
*/
/*
console.log("Pop Method in Array")
let Vehicle=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
console.log("The Original Array is : ",Vehicle)
Vehicle.pop()
Vehicle.pop("Rangerover")
console.log("The Array After Pop : ",Vehicle)
*/
/*
console.log("Concat Method in Array")
let Cars=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
let Bykes=["Hero","Honda","Bajaj","Kawasaki"]
let newarr=Cars.concat(Bykes)
console.log(newarr)
*/
/*
console.log("unShift Method in Array")
let Cars=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
Cars.unshift("Hero","Honda","Mahindra","Thar")
console.log(Cars)
*/
/*
console.log("shift Method in Array")
let Cars=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
Cars.shift()
console.log(Cars)
*/
/*
console.log("slice Method in Array")
let Cars=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
console.log("Original Array : ",Cars)
let updatedarray=Cars.slice(0,3)
console.log("Sliced Array : ",updatedarray)
*/
/*
console.log("splice Method in Array")
let Cars=["Maruti Suzuki","Toyota","Rangerover","Bmw","Audi","Tata","Hundai","Roles"]
console.log("Old Array : ",Cars)
Cars.splice(3,3,"Bajaj","KTM","Mahindra")
console.log("Spliced Array : ",Cars)
*/
console.log("Practice Question")
let companies=["Bloomberg","Microsoft","Uber","Google","IBM","Netflix"]
console.log("Old Array : ",companies)
companies.shift()
console.log("First Updated Array : ",companies)
companies.splice(1,1,"Ola")
console.log("Second Updated Array : ",companies)
companies.push("Amazon")
console.log("Third Updated Array : ",companies)