Skip to content

Commit 119c11b

Browse files
committed
array PS completed
1 parent 1357c74 commit 119c11b

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

ary.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// PS - Chp 5 [array]
2+
3+
//que1
4+
/*
5+
let n = prompt("enter length of array")
6+
let ary = [n]
7+
for(let i=0;i<n;i++)
8+
{
9+
ary[i] = prompt("enter value in array")
10+
}
11+
for(let j=0;j<n;j++)
12+
{
13+
ary[j] = Number.parseInt(ary[j])
14+
console.log(ary[j])
15+
console.log(typeof ary[j])
16+
}
17+
let arr = [1,2,3,4,5]
18+
let a = prompt("enter a number")
19+
a = parseInt(a)
20+
arr.push(a)
21+
console.log(arr)
22+
console.log(typeof arr)
23+
*/
24+
25+
//array sort method
26+
/*
27+
let arr=[11,155,9,3,0,5,-5]
28+
console.log(arr.sort()) //sort alphabettical order
29+
let compare1 = (a,b) =>{
30+
return a-b //sort assending order
31+
}
32+
33+
let compare2 = (a,b) =>{
34+
return b-a //sort desendinf order
35+
}
36+
console.log(arr.sort(compare1))
37+
console.log(arr.sort(compare2))
38+
*/
39+
40+
//array map method
41+
/*
42+
let arr = [1,2,3]
43+
let a = arr.map((value,index,array) => {
44+
console.log(value,index,array)
45+
return i+j
46+
})
47+
console.log(a)
48+
*/
49+
50+
//array filter method
51+
/*
52+
let arr=[11,12,15,1,5,6]
53+
let a = arr.filter((value) =>{
54+
return value>10
55+
})
56+
console.log(a)
57+
*/
58+
59+
//array reduce method
60+
/*
61+
let arr=[1,3,4,5,4,6]
62+
let add=(a1,a2) => {
63+
return a1+a2
64+
}
65+
let a = arr.reduce(add)
66+
console.log(a)
67+
*/
68+
69+
//que2
70+
/*
71+
let ary = [1,2,3,4]
72+
let a = prompt("enter value in array")
73+
for(;a!=0;)
74+
{
75+
ary.push(a)
76+
a= prompt("enter value in array")
77+
if(a==0)
78+
{
79+
break
80+
}
81+
}
82+
console.log(ary)
83+
*/
84+
85+
//que3
86+
/*
87+
let ary = [10,15,20,25,30]
88+
let a = ary.filter((value)=>{
89+
return value%10==0
90+
})
91+
console.log(a)
92+
*/
93+
94+
//que4
95+
/*
96+
let ary = [1,2,3,4,5]
97+
let new_ary = ary.map((a)=>{
98+
return a*a
99+
})
100+
console.log(new_ary)
101+
*/
102+
103+
//que5
104+
/*
105+
let n = prompt("enter number")
106+
let ary=[n]
107+
for(let i=0;i<n;i++)
108+
{
109+
ary[i] = prompt("enter value in array")
110+
}
111+
console.log(ary)
112+
let fact = ary.reduce((x1,x2)=>{
113+
return x1*x2
114+
})
115+
console.log("factorial is : " +fact)
116+
*/
117+
118+
119+
120+
121+
122+
123+
124+
125+

0 commit comments

Comments
 (0)