presudo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ // Transaction.ts
2
+
3
+ class Transaction {
4
+ transactionId: string;
5
+ amount: number;
6
+ date: Date;
7
+ type: "debit" | "credit";
8
+ description: string;
9
+
10
+ constructor(transactionId: string, amount: number, date: Date, type: "debit" | "credit", description: string) {
11
+ this.transactionId = transactionId;
12
+ this.amount = amount;
13
+ this.date = date;
14
+ this.type = type;
15
+ this.description = description;
16
+ }
17
+
18
+ // Method to display transaction details
19
+ displayTransaction(): void {
20
+ console.log(`Transaction ID: ${this.transactionId}`);
21
+ console.log(`Amount: $${this.amount}`);
22
+ console.log(`Date: ${this.date.toLocaleDateString()}`);
23
+ console.log(`Type: ${this.type}`);
24
+ console.log(`Description: ${this.description}`);
25
+ }
26
+
27
+ // Method to get the transaction's positive or negative balance effect
28
+ getBalanceEffect(): number {
29
+ return this.type === "debit" ? -this.amount : this.amount;
30
+ }
31
+ }
32
+
33
+ // Example usage:
34
+
35
+ const transaction1 = new Transaction("T001", 150, new Date(), "credit", "Payment for invoice #123");
36
+ transaction1.displayTransaction();
37
+ console.log(`Balance effect: $${transaction1.getBalanceEffect()}`);
38
+
39
+ const transaction2 = new Transaction("T002", 50, new Date(), "debit", "Purchase at retail store");
40
+ transaction2.displayTransaction();
41
+ console.log(`Balance effect: $${transaction2.getBalanceEffect()}`);
@@ -0,0 +1,39 @@
1
+ // Book.ts
2
+
3
+ class Book {
4
+ title: string;
5
+ author: string;
6
+ publicationYear: number;
7
+ genre: string;
8
+
9
+ constructor(title: string, author: string, publicationYear: number, genre: string) {
10
+ this.title = title;
11
+ this.author = author;
12
+ this.publicationYear = publicationYear;
13
+ this.genre = genre;
14
+ }
15
+
16
+ // Method to display book details
17
+ displayDetails(): void {
18
+ console.log(`Title: ${this.title}`);
19
+ console.log(`Author: ${this.author}`);
20
+ console.log(`Year of Publication: ${this.publicationYear}`);
21
+ console.log(`Genre: ${this.genre}`);
22
+ }
23
+
24
+ // Method to check if the book is old (more than 50 years)
25
+ isOld(): boolean {
26
+ const currentYear = new Date().getFullYear();
27
+ return currentYear - this.publicationYear > 50;
28
+ }
29
+ }
30
+
31
+ // Example usage:
32
+
33
+ const book1 = new Book("1984", "George Orwell", 1949, "Dystopian");
34
+ book1.displayDetails();
35
+ console.log(`Is it an old book? ${book1.isOld() ? "Yes" : "No"}`);
36
+
37
+ const book2 = new Book("The Catcher in the Rye", "J.D. Salinger", 1951, "Fiction");
38
+ book2.displayDetails();
39
+ console.log(`Is it an old book? ${book2.isOld() ? "Yes" : "No"}`);
@@ -0,0 +1,7 @@
1
+ // find avg marks
2
+
3
+
4
+ export function findAvg(marks: number[]): number {
5
+ //you have to complete logic
6
+ return ((85 + 92 + 78 + 90 + 88) / 5);
7
+ }
@@ -0,0 +1,12 @@
1
+ // managing product inventory
2
+
3
+ export function displayProducts(names:string[],prices:number[]):void{
4
+ for (let i = 0; i < names.length; i++) {
5
+ console.log(`Product Name: ${names[i]}, Price: $${prices[i]}`);
6
+ }
7
+ }
8
+ export function findAvg(prices:number[]):number{
9
+ let sum=0;
10
+ for(let i=0;i<prices.length;i++)sum+=prices[i];
11
+ return sum/prices.length;
12
+ }
@@ -0,0 +1,341 @@
1
+ 1. Filter Even Numbers from an Array
2
+
3
+ Question: Write a TypeScript program to filter all the even numbers from an array using the filter() method.
4
+
5
+ const numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
6
+
7
+ // Filter out even numbers
8
+ const evenNumbers = numbers.filter((num) => num % 2 === 0);
9
+
10
+ console.log("Even Numbers:", evenNumbers);
11
+
12
+
13
+ Explanation:
14
+
15
+ filter() returns a new array that includes only the elements where the condition (even numbers in this case) is true.
16
+
17
+ ----------------------------------------------------------------------------------------------------------------------------------------------
18
+
19
+ 2. Sum of Array Elements Using reduce()
20
+
21
+ Question: Write a TypeScript program to find the sum of all numbers in an array using the reduce() method.
22
+
23
+ const numbers: number[] = [10, 20, 30, 40, 50];
24
+
25
+ // Find the sum of the array using reduce
26
+ const sum = numbers.reduce((acc, num) => acc + num, 0);
27
+
28
+ console.log("Sum of Array:", sum);
29
+
30
+
31
+ Explanation:
32
+
33
+ reduce() accumulates the result by applying the provided function to each element in the array, starting from an initial value of 0.
34
+ ----------------------------------------------------------------------------------------------------------------------------------------------
35
+
36
+ 3. Double the Values in an Array
37
+
38
+ Question: Write a TypeScript program that doubles the value of each element in an array using the map() method.
39
+
40
+ const numbers: number[] = [2, 4, 6, 8, 10];
41
+
42
+ // Double each number in the array
43
+ const doubledNumbers = numbers.map((num) => num * 2);
44
+
45
+ console.log("Doubled Numbers:", doubledNumbers);
46
+
47
+
48
+ Explanation:
49
+
50
+ map() creates a new array where each element is the result of applying the transformation (doubling in this case) to each element of the original array.
51
+ ----------------------------------------------------------------------------------------------------------------------------------------------
52
+
53
+ 4. Filter Students Based on Marks
54
+
55
+ Question: Given a list of students with their marks, filter out the students who scored above 70 marks using the filter() method.
56
+
57
+ const students = [
58
+ { name: "Alice", marks: 85 },
59
+ { name: "Bob", marks: 65 },
60
+ { name: "Charlie", marks: 90 },
61
+ { name: "David", marks: 72 },
62
+ ];
63
+
64
+ // Filter students who scored above 70 marks
65
+ const studentsAbove70 = students.filter((student) => student.marks > 70);
66
+
67
+ console.log("Students with marks above 70:", studentsAbove70);
68
+
69
+
70
+ Explanation:
71
+
72
+ filter() is used to return a new array that contains only the students who scored above 70.
73
+ ----------------------------------------------------------------------------------------------------------------------------------------------
74
+
75
+ 5. Find Maximum Element in an Array
76
+
77
+ Question: Write a TypeScript program that finds the maximum number in an array using Math.max() with the spread operator.
78
+
79
+ const numbers: number[] = [10, 20, 30, 40, 50];
80
+
81
+ // Find the maximum number in the array
82
+ const maxNumber = Math.max(...numbers);
83
+
84
+ console.log("Maximum Number:", maxNumber);
85
+
86
+
87
+ Explanation:
88
+
89
+ Math.max() is used to find the maximum value in an array. The spread operator ... is used to unpack the elements of the array into the Math.max() function.
90
+ ----------------------------------------------------------------------------------------------------------------------------------------------
91
+
92
+ 6. Convert Array of Strings to Uppercase
93
+
94
+ Question: Given an array of strings, write a program to convert all strings to uppercase using map().
95
+
96
+ const words: string[] = ["hello", "world", "typescript", "programming"];
97
+
98
+ // Convert all words to uppercase
99
+ const uppercaseWords = words.map((word) => word.toUpperCase());
100
+
101
+ console.log("Uppercase Words:", uppercaseWords);
102
+
103
+
104
+ Explanation:
105
+
106
+ map() is used to apply toUpperCase() on each string in the array, transforming all strings to uppercase.
107
+ ----------------------------------------------------------------------------------------------------------------------------------------------
108
+
109
+ 7. Find Odd Numbers Using filter()
110
+
111
+ Question: Write a TypeScript program to filter out all the odd numbers from an array using the filter() method.
112
+
113
+ const numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
114
+
115
+ // Filter out odd numbers from the array
116
+ const oddNumbers = numbers.filter((num) => num % 2 !== 0);
117
+
118
+ console.log("Odd Numbers:", oddNumbers);
119
+
120
+
121
+ Explanation:
122
+
123
+ filter() is used to find numbers that are not divisible by 2 (odd numbers).
124
+ ----------------------------------------------------------------------------------------------------------------------------------------------
125
+
126
+ 8. Flatten a Nested Array
127
+
128
+ Question: Write a TypeScript program to flatten a nested array (array of arrays) into a single array using the flat() method.
129
+
130
+ const nestedArray: number[][] = [[1, 2, 3], [4, 5, 6], [7, 8]];
131
+
132
+ // Flatten the nested array into a single array
133
+ const flattenedArray = nestedArray.flat();
134
+
135
+ console.log("Flattened Array:", flattenedArray);
136
+
137
+ Explanation:
138
+
139
+ flat() is used to merge all inner arrays into a single array.
140
+ ----------------------------------------------------------------------------------------------------------------------------------------------
141
+
142
+ 9. Iterate Over Array of Objects Using forEach()
143
+
144
+ Question: Write a TypeScript program to iterate over an array of objects and display their properties using forEach().
145
+
146
+ const users = [
147
+ { name: "John", age: 25 },
148
+ { name: "Jane", age: 30 },
149
+ { name: "Jake", age: 35 },
150
+ ];
151
+
152
+ // Iterate over users and log their names and ages
153
+ users.forEach((user) => {
154
+ console.log(`${user.name}: ${user.age}`);
155
+ });
156
+
157
+
158
+ Explanation:
159
+
160
+ forEach() is used to iterate over each object in the array and log its properties.
161
+ ----------------------------------------------------------------------------------------------------------------------------------------------
162
+
163
+ 10. Find the Index of an Element in an Array
164
+
165
+ Question: Write a TypeScript program that finds the index of a specific number in an array using the indexOf() method.
166
+
167
+ const numbers: number[] = [10, 20, 30, 40, 50];
168
+
169
+ // Find the index of the number 30 in the array
170
+ const index = numbers.indexOf(30);
171
+
172
+ console.log("Index of 30:", index);
173
+
174
+
175
+ Explanation:
176
+
177
+ indexOf() returns the index of the first occurrence of the specified element in the array.
178
+
179
+ ----------------------------------------------------------------------------------------------------------------------------------------------
180
+
181
+ 11. Complex Filtering and Mapping
182
+
183
+ Question: You have an array of products with their names and prices. Write a program that returns an array of products that cost more than $50 and sorts them in ascending order by price.
184
+
185
+ const products = [
186
+ { name: "Laptop", price: 800 },
187
+ { name: "Phone", price: 600 },
188
+ { name: "Tablet", price: 200 },
189
+ { name: "Monitor", price: 150 },
190
+ { name: "Keyboard", price: 50 },
191
+ ];
192
+
193
+ // Filter products that cost more than $50 and sort them by price
194
+ const filteredAndSortedProducts = products
195
+ .filter((product) => product.price > 50)
196
+ .sort((a, b) => a.price - b.price);
197
+
198
+ console.log("Filtered and Sorted Products:", filteredAndSortedProducts);
199
+
200
+ Explanation:
201
+
202
+ filter() filters out products that cost more than $50, and sort() arranges the filtered products
203
+ by their price in ascending order.
204
+ ----------------------------------------------------------------------------------------------------------------------------------------------
205
+
206
+ 12. Array Manipulation and Display
207
+
208
+ Question: Write a program that takes an array of student names and their scores. Display the student names and their scores, then calculate and display the highest score using reduce().
209
+
210
+ const students = [
211
+ { name: "Alice", score: 85 },
212
+ { name: "Bob", score: 92 },
213
+ { name: "Charlie", score: 76 },
214
+ { name: "David", score: 89 },
215
+ ];
216
+
217
+ // Display student names and scores
218
+ students.forEach((student) => {
219
+ console.log(`${student.name}: ${student.score}`);
220
+ });
221
+
222
+ // Find the highest score using reduce
223
+ const highestScore = students.reduce(
224
+ (max, student) => (student.score > max ? student.score : max),
225
+ 0
226
+ );
227
+
228
+ console.log("Highest Score:", highestScore);
229
+
230
+
231
+ Explanation:
232
+
233
+ forEach() is used to display each student's name and score. reduce() finds the highest score.
234
+ ----------------------------------------------------------------------------------------------------------------------------------------------
235
+
236
+ 13. Grouping and Summing Data
237
+
238
+ Question: Given an array of numbers, write a program to sum the numbers and group them into 'even' and 'odd' arrays using the reduce() method.
239
+
240
+ const numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
241
+
242
+ // Group numbers into even and odd arrays
243
+ const grouped = numbers.reduce(
244
+ (acc, num) => {
245
+ if (num % 2 === 0) {
246
+ acc.even.push(num);
247
+ } else {
248
+ acc.odd.push(num);
249
+ }
250
+ return acc;
251
+ },
252
+ { even: [], odd: [] }
253
+ );
254
+
255
+ console.log("Even Numbers:", grouped.even);
256
+ console.log("Odd Numbers:", grouped.odd);
257
+
258
+
259
+ Explanation:
260
+
261
+ reduce() groups numbers into two categories, even and odd, by checking the divisibility by 2.
262
+ ----------------------------------------------------------------------------------------------------------------------------------------------
263
+
264
+ 14. Remove Elements from Array
265
+
266
+ Question: Write a program to remove all elements that are less than 5 from an array of numbers using filter().
267
+
268
+ const numbers: number[] = [1, 3, 5, 7, 2, 4, 6, 8];
269
+
270
+ // Remove elements that are less than 5
271
+ const filteredNumbers = numbers.filter((num) => num >= 5);
272
+
273
+ console.log("Numbers greater than or equal to 5:", filteredNumbers);
274
+
275
+
276
+ Explanation:
277
+
278
+ filter() is used to remove all numbers less than 5 by only keeping the numbers that satisfy the condition (num >= 5).
279
+ ----------------------------------------------------------------------------------------------------------------------------------------------
280
+
281
+ 15. Dynamic Filtering and Transformation
282
+
283
+ Question: Write a program that accepts a filter condition (e.g., above 50, below 10) as input, filters the array accordingly, and then maps the filtered array to square the values.
284
+
285
+ const numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
286
+
287
+ // Define a filter condition (for example: above 5)
288
+ const condition = (num: number) => num > 5;
289
+
290
+ // Filter and map to square the filtered numbers
291
+ const result = numbers.filter(condition).map((num) => num ** 2);
292
+
293
+ console.log("Filtered and Squared Numbers:", result);
294
+
295
+
296
+ Explanation:
297
+
298
+ filter() applies the condition, and map() squares each element of the filtered array.
299
+ ----------------------------------------------------------------------------------------------------------------------------------------------
300
+
301
+ 16. Deep Object Filtering and Manipulation
302
+
303
+ Question: Given an array of employees where each employee has a name, age, and department, write a program that finds all employees in the 'HR' department and sorts them by age in descending order.
304
+
305
+ const employees = [
306
+ { name: "John", age: 25, department: "HR" },
307
+ { name: "Jane", age: 30, department: "Engineering" },
308
+ { name: "Jake", age: 35, department: "HR" },
309
+ { name: "Jill", age: 28, department: "Marketing" },
310
+ ];
311
+
312
+ // Find HR employees and sort by age descending
313
+ const hrEmployees = employees
314
+ .filter((employee) => employee.department === "HR")
315
+ .sort((a, b) => b.age - a.age);
316
+
317
+ console.log("HR Employees sorted by age:", hrEmployees);
318
+
319
+
320
+ Explanation:
321
+
322
+ filter() finds employees in the 'HR' department, and sort() sorts them by age in descending order.
323
+ ----------------------------------------------------------------------------------------------------------------------------------------------
324
+
325
+ 17. Flatten and Transform Data
326
+
327
+ Question: Given a nested array, write a program that flattens it and then filters out any non-numeric values before mapping it to the square of each number.
328
+
329
+ const nestedArray: any[] = [[1, 2, "a"], [4, "b", 6], [7, "c"]];
330
+
331
+ // Flatten, filter non-numeric values, and square the remaining numbers
332
+ const transformedArray = nestedArray
333
+ .flat()
334
+ .filter((item) => typeof item === "number")
335
+ .map((num) => num ** 2);
336
+
337
+ console.log("Transformed Array:", transformedArray);
338
+
339
+ Explanation:
340
+
341
+ flat() flattens the nested array, filter() removes non-numeric values, and map() squares the remaining numbers.
package/test.js ADDED
@@ -0,0 +1,3 @@
1
+ const { startRide } = require("./index");
2
+
3
+ console.log(startRide("Abhi bro 😎"));