-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatterns.js
More file actions
168 lines (127 loc) · 3.72 KB
/
patterns.js
File metadata and controls
168 lines (127 loc) · 3.72 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// let p = 'A';
// let n = 5;
// for (let i = 1; i <= n; i++) {
// for (let j = 1; j <= i; j++) {
// process.stdout.write(p + "\t"); // Write the character with a tab
// p = String.fromCharCode(p.charCodeAt(0) + 1); // Increment character
// }
// console.log(); // Move to the next line after each row
// }
// let p='A',n=5;
// for (let i = 1; i <=n; i++) {
// for(let j=1;j<=i;j++)
// {
// process.stdout.write((CharacterData)p);
// p++;
// }
// System.out.println();
// }
// let p = 'A';
// let n = 5; // Number of rows
// for (let i = 1; i <= n; i++) {
// let output = '';
// // Add spaces for centering the pyramid
// for (let j = 1; j <= n - i; j++) {
// output += ' \t'; // Add tabs to create spaces
// }
// // Add the letters for the current row
// for (let k = 1; k <= i; k++) {
// output += p + "\t";
// p = String.fromCharCode(p.charCodeAt(0) + 1); // Move to the next character
// }
// console.log(output); // Print the current row
// }
// let p = 'A';
// let n = 5; // Number of rows
// for (let i = 1; i <= n; i++) {
// let output = '';
// for (let j = 1; j <= i; j++) {
// output += p + "\t";
// p = String.fromCharCode(p.charCodeAt(0) + 1);
// }
// console.log(output);
// }
// let p = 'A';
// let n = 5; // Number of rows
// for (let i = n; i >= 1; i--) {
// let output = '';
// for (let j = 1; j <= i; j++) {
// output += p + "\t";
// p = String.fromCharCode(p.charCodeAt(0) + 1);
// }
// console.log(output);
// }
// let rem, reverse = 0, copy, i, j;
// for (i = 153; i <= 999; i++) {
// copy = i;
// j = i;
// while (j != 0) {
// rem = j % 10;
// reverse += rem * rem * rem;
// j = Math.floor(j / 10);
// }
// if (copy == reverse)
// console.log("Armstrong: " + i);
// reverse = 0; // Reset reverse for the next iteration
// }
// let num = 1;
// for (let i = 0; i <= 10; i++) {
// for (let j = 1; j <= 10; j++) {
// console.log(num + " x " + j + " = " + (num * j));
// }
// console.log(); // Print a blank line between tables
// num++;
// }
// function checkEvenOdd(number) {
// if (number % 2 === 0) {
// return "Even";
// } else {
// return "Odd";
// }
// }
// // Test the function
// console.log("4 is:", checkEvenOdd(4)); // Even
// console.log("7 is:", checkEvenOdd(7)); // Odd
// function sumArray(numbers) {
// let sum = 0;
// for (let i = 0; i < numbers.length; i++) {
// sum += numbers[i];
// }
// return sum;
// }
// // Test the function
// let numbersArray = [1, 2, 3, 4, 5];
// console.log("Sum of array:", sumArray(numbersArray)); // 15
// function isPrime(num) {
// if (num <= 1) return false;
// for (let i = 2; i < num; i++) {
// if (num % i === 0) return false;
// }
// return true;
// }
// for (let i = 1; i <= 100; i++) {
// if (isPrime(i)) console.log(i);
// }
// function fibonacci(n) {
// let a = 0, b = 1, next;
// for (let i = 1; i <= n; i++) {
// console.log(a);
// next = a + b;
// a = b;
// b = next;
// }
// }
// fibonacci(10); // Output: first 10 numbers in the Fibonacci sequence
// let person = {
// name: "Alice",
// age: 30,
// introduce: function() {
// return `Hi, my name is ${this.name} and I am ${this.age} years old.`;
// }
// };
// // Use the method
// console.log(person.introduce());
let numbers = [1, 6, 3, 8, 2, 10, 4];
// Filter and sort
let filteredAndSorted = numbers.filter(num => num <= 5).sort((a, b) => b - a);
console.log("Filtered and Sorted:", filteredAndSorted);