-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.js
90 lines (71 loc) · 1.7 KB
/
practice.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
// // for (let i = 1; i <=10; i++) {
// // console.log(i);
// // }
// for (let i = 1; i <=10; i++) {
// let b=5*i;
// console.log(b);
// }
// // let a =10;
// // while (a>=1) {
// // console.log(a);
// // a--;
// // }
// let a=1;
// sum=0;
// while (a<=10) {
// sum+=a;
// a++
// console.log(sum);
// }
// let num = 5;
// let factorial = 1;
// do {
// factorial *=num;
// num --;
// } while (num>=1);
// console.log(factorial);
let num = 5;
let factorial = 1;
for (let index = num; index > 1; index--) {
factorial *=index;
//console.log(factorial);
}
console.log(factorial);
let rows = 5;
for (let i = 5; i >=1; i--) {
let stars = "";
// for (let j = -1; j <=i; j++) {
for (let j = 1; j <=i; j++) //printing for column
{
stars += "*";
// console.log(stars);
}
console.log(stars);
}
// let row = 5;
// for (let a = 1; a <= row; a++) {
// let stars = ""
// for (let b = 1; b <= row; b++) {
// stars +="*"
// }
// console.log(stars);
// }
let row = 5;
for (let a = 1; a <= row; a++) {
let stars = ""
for (let b = 1; b <= a; b++) {
stars += b + " "
}
console.log(stars);
}
// const Arr= [1,2,3,4,5,]
// const maxArr = Arr.reduce((acccumulator, currentValue) =>
// Math.max(acccumulator, currentValue, -Infinity)
// )
// console.log(`Maximum value in the array ${maxArr}`);
const fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']
const fruitCount =fruits.reduce((acccumulator, currentValue) => {
acccumulator[currentValue] = (acccumulator[currentValue] || 0)+1;
return acccumulator;
},{})
console.log(fruitCount);