├── Question-60 ├── node_modules │ ├── @types │ │ └── node │ │ │ ├── globals.global.d.ts │ │ │ ├── assert │ │ │ └── strict.d.ts │ │ │ ├── constants.d.ts │ │ │ ├── stream │ │ │ ├── consumers.d.ts │ │ │ └── promises.d.ts │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── string_decoder.d.ts │ │ │ ├── timers │ │ │ └── promises.d.ts │ │ │ └── index.d.ts │ ├── undici-types │ │ ├── header.d.ts │ │ ├── global-origin.d.ts │ │ ├── interceptors.d.ts │ │ ├── global-dispatcher.d.ts │ │ ├── mock-errors.d.ts │ │ ├── handlers.d.ts │ │ ├── README.md │ │ ├── content-type.d.ts │ │ ├── balanced-pool.d.ts │ │ ├── pool-stats.d.ts │ │ ├── cookies.d.ts │ │ ├── proxy-agent.d.ts │ │ ├── mock-pool.d.ts │ │ ├── mock-client.d.ts │ │ ├── pool.d.ts │ │ ├── connector.d.ts │ │ ├── agent.d.ts │ │ ├── cache.d.ts │ │ ├── package.json │ │ ├── api.d.ts │ │ ├── filereader.d.ts │ │ ├── file.d.ts │ │ ├── readable.d.ts │ │ ├── diagnostics-channel.d.ts │ │ ├── patch.d.ts │ │ ├── mock-agent.d.ts │ │ ├── index.d.ts │ │ ├── websocket.d.ts │ │ ├── mock-interceptor.d.ts │ │ ├── errors.d.ts │ │ └── client.d.ts │ └── .package-lock.json ├── package.json ├── index.js ├── package-lock.json └── index.ts ├── Question-88 ├── main.js └── main.ts ├── Question-89 ├── main.ts └── main.js ├── Question-90 ├── main.ts └── main.js ├── Question-94 ├── main.js └── main.ts ├── 45-Assignment-Q01 ├── main.js ├── main.ts └── package.json ├── Question-87 ├── main.ts └── main.js ├── Question-85 ├── main.js └── main.ts ├── Question-95 ├── main.js └── main.ts ├── Question-86 ├── main.ts └── main.js ├── Question-57 ├── main.ts └── main.js ├── 45-Assignment-Q08 ├── main.js └── main.ts ├── Question-91 ├── main.js └── main.ts ├── Question-55 ├── main.js └── main.ts ├── Question-56 ├── main.ts └── main.js ├── 45-Assignment-Q09 ├── main.js └── main.ts ├── Question-96 ├── main.js └── main.ts ├── 45-Assignment-Q02 ├── main.ts └── main.js ├── 45-Assignment-Q03 ├── main.js └── main.ts ├── Question-84 ├── main.ts └── main.js ├── Question-92 ├── main.js └── main.ts ├── Question-82 ├── index.ts └── index.js ├── 45-Assignment-Q21 ├── main.js └── main.ts ├── Question-54 ├── main.js └── main.ts ├── Question-76 ├── main.js └── main.ts ├── Question-93 ├── main.js └── main.ts ├── Question-70 ├── index.ts └── index.js ├── 45-Assignment-Q19 ├── main.js └── main.ts ├── Question-68 ├── index.js └── index.ts ├── 45-Assignment-Q11 ├── main.js └── main.ts ├── Question-79 ├── main.ts └── main.js ├── 45-Assignment-Q20 ├── main.ts └── main.js ├── 45-Assignment-Q05 ├── main.js └── main.ts ├── 45-Assignment-Q14 ├── main.ts └── main.js ├── Question-49 ├── main.ts └── main.js ├── Question-63 ├── index.js └── index.ts ├── Question-65 ├── index.js └── index.ts ├── Question-98 ├── main.ts └── main.js ├── Question-48 ├── index.ts └── index.js ├── 45-Assignment-Q41 ├── main.js └── main.ts ├── Question-51 ├── main.js └── main.ts ├── Question-64 ├── index.js └── index.ts ├── Question-46 ├── index.ts └── index.js ├── Question-67 ├── index.ts └── index.js ├── Question-83 ├── main.ts └── main.js ├── Question-77 ├── main.js └── main.ts ├── 45-Assignment-Q04 ├── main.ts └── main.js ├── Question-97 ├── main.ts └── main.js ├── Question-58 ├── index.js └── index.ts ├── 45-Assignment-Q36 ├── main.js └── main.ts ├── Question-66 ├── index.js └── index.ts ├── 45-Assignment-Q13 ├── main.ts └── main.js ├── 45-Assignment-Q40 ├── main.js └── main.ts ├── Question-99 ├── main.js └── main.ts ├── 45-Assignment-Q31 ├── main.js └── main.ts ├── Question-52 ├── main.ts └── main.js ├── Question-80 ├── main.ts └── main.js ├── 45-Assignment-Q06 ├── main.js └── main.ts ├── Question-59 ├── index.js └── index.ts ├── Question-78 ├── main.js └── main.ts ├── 45-Assignment-Q22 ├── main.js └── main.ts ├── Question-61 ├── index.ts └── index.js ├── Question-71 ├── index.ts └── index.js ├── Question-81 ├── main.ts └── main.js ├── Question-73 ├── main.ts └── main.js ├── 45-Assignment-Q39 ├── main.js └── main.ts ├── Question-69 ├── index.js └── index.ts ├── 45-Assignment-Q07 ├── main.js └── main.ts ├── 45-Assignment-Q12 ├── main.ts └── main.js ├── Question-47 ├── index.js └── index.ts ├── Question-74 ├── main.ts └── main.js ├── 45-Assignment-Q38 ├── main.js └── main.ts ├── Question-53 ├── main.ts └── main.js ├── Question-62 ├── main.js └── main.ts ├── Question-50 ├── main.ts └── main.js ├── 45-Assignment-Q37 ├── main.ts └── main.js ├── 45-Assignment-Q42 ├── main.js └── main.ts ├── 45-Assignment-Q10 ├── main.js └── main.ts ├── 45-Assignment-Q44 ├── main.ts └── main.js ├── 45-Assignment-Q25 ├── main.js └── main.ts ├── 45-Assignment-Q26 ├── main.js └── main.ts ├── 45-Assignment-Q30 ├── main.ts └── main.js ├── 45-Assignment-Q33 ├── main.ts └── main.js ├── Question-75 ├── main.ts └── main.js ├── 45-Assignment-Q34 ├── main.ts └── main.js ├── Question-72 ├── index.ts └── index.js ├── 45-Assignment-Q45 ├── main.ts └── main.js ├── 45-Assignment-Q35 ├── main.ts └── main.js ├── 45-Assignment-Q29 ├── main.js └── main.ts ├── 45-Assignment-Q27 ├── main.ts └── main.js ├── 45-Assignment-Q28 ├── main.ts └── main.js ├── 45-Assignment-Q43 ├── main.ts └── main.js ├── 45-Assignment-Q17 ├── main.ts └── main.js ├── 45-Assignment-Q32 ├── main.ts └── main.js ├── 45-Assignment-Q16 ├── main.ts └── main.js ├── 45-Assignment-Q15 ├── main.ts └── main.js ├── 45-Assignment-Q23 ├── main.js └── main.ts ├── 45-Assignment-Q24 ├── main.js └── main.ts └── 45-Assignment-Q18 ├── main.js └── main.ts /Question-60/node_modules/@types/node/globals.global.d.ts: -------------------------------------------------------------------------------- 1 | declare var global: typeof globalThis; 2 | -------------------------------------------------------------------------------- /Question-88/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Make a function that convert string to number 3 | const convert = (str) => Number(str); 4 | console.log(convert("123")); // 123 5 | -------------------------------------------------------------------------------- /Question-88/main.ts: -------------------------------------------------------------------------------- 1 | // Make a function that convert string to number 2 | const convert = (str:string): number => Number(str); 3 | console.log(convert("123")); // 123 4 | -------------------------------------------------------------------------------- /Question-89/main.ts: -------------------------------------------------------------------------------- 1 | // make a funtion that converts a decimal into two decimal places 2 | const decimal = (num:number): number => Number(num.toFixed(2)); 3 | console.log(decimal(3.12231)); 4 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/header.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The header type declaration of `undici`. 3 | */ 4 | export type IncomingHttpHeaders = Record; 5 | -------------------------------------------------------------------------------- /Question-89/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // make a funtion that converts a decimal into two decimal places 3 | const decimal = (num) => Number(num.toFixed(2)); 4 | console.log(decimal(3.12231)); 5 | -------------------------------------------------------------------------------- /Question-90/main.ts: -------------------------------------------------------------------------------- 1 | // make a function that generates random number b/w 1-10 2 | const generate = (): void => console.log(Math.floor(Math.random() * 10) + 1); 3 | generate(); 4 | generate(); 5 | generate(); -------------------------------------------------------------------------------- /Question-90/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // make a function that generates random number b/w 1-10 3 | const generate = () => console.log(Math.floor(Math.random() * 10) + 1); 4 | generate(); 5 | generate(); 6 | generate(); 7 | -------------------------------------------------------------------------------- /Question-94/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Define array of words and find the length of all 3 | const words = ["Hello", "World", "TypeScript", "JavaScript"]; 4 | const lengths = words.map(val => val.length); 5 | console.log(lengths); 6 | -------------------------------------------------------------------------------- /45-Assignment-Q01/main.js: -------------------------------------------------------------------------------- 1 | // 1. Install [Node.js](https://nodejs.org/en/), [TypeScript](https://www.typescriptlang.org/download) 2 | // and [VS Code](https://code.visualstudio.com/) on your computer. 3 | // I Installed All Of This Things 4 | -------------------------------------------------------------------------------- /45-Assignment-Q01/main.ts: -------------------------------------------------------------------------------- 1 | // 1. Install [Node.js](https://nodejs.org/en/), [TypeScript](https://www.typescriptlang.org/download) 2 | // and [VS Code](https://code.visualstudio.com/) on your computer. 3 | 4 | // I Installed All Of This Things -------------------------------------------------------------------------------- /Question-87/main.ts: -------------------------------------------------------------------------------- 1 | // make the function that takes out the first 10 characters from any text 2 | const takeOut = (str: string): string => str.substring(0, 10); 3 | console.log(takeOut("I Have Completed My Assignments")); // Takeout 10 Letters 4 | -------------------------------------------------------------------------------- /Question-94/main.ts: -------------------------------------------------------------------------------- 1 | // Define array of words and find the length of all 2 | const words: string[] = ["Hello", "World", "TypeScript", "JavaScript"]; 3 | const lengths: number[] = words.map(val => val.length); 4 | console.log(lengths); 5 | 6 | 7 | -------------------------------------------------------------------------------- /Question-87/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // make the function that takes out the first 10 characters from any text 3 | const takeOut = (str) => str.substring(0, 10); 4 | console.log(takeOut("I Have Completed My Assignments")); // Takeout 10 Letters 5 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/global-origin.d.ts: -------------------------------------------------------------------------------- 1 | export { 2 | setGlobalOrigin, 3 | getGlobalOrigin 4 | } 5 | 6 | declare function setGlobalOrigin(origin: string | URL | undefined): void; 7 | declare function getGlobalOrigin(): URL | undefined; -------------------------------------------------------------------------------- /Question-85/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Q-85 Make a Function which finds where "code" first shows up in a text 3 | function find(str) { 4 | return str.indexOf("code"); 5 | } 6 | console.log("The index of code is: ", find("I am writing a code")); 7 | -------------------------------------------------------------------------------- /Question-95/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // make function which filter number greater then 10; 3 | function filterNumber(arr) { 4 | return arr.filter(val => val > 10); 5 | } 6 | console.log(filterNumber([5, 10, 15, 20, 25, 30])); // [15, 20, 25, 30] 7 | -------------------------------------------------------------------------------- /Question-95/main.ts: -------------------------------------------------------------------------------- 1 | // make function which filter number greater then 10; 2 | function filterNumber(arr: number[]): number[] { 3 | return arr.filter(val => val > 10); 4 | } 5 | console.log(filterNumber([5, 10, 15, 20, 25, 30])); // [15, 20, 25, 30] 6 | -------------------------------------------------------------------------------- /Question-85/main.ts: -------------------------------------------------------------------------------- 1 | // Q-85 Make a Function which finds where "code" first shows up in a text 2 | 3 | function find(str: string): number { 4 | return str.indexOf("code"); 5 | } 6 | 7 | console.log("The index of code is: ",find("I am writing a code")); 8 | -------------------------------------------------------------------------------- /Question-86/main.ts: -------------------------------------------------------------------------------- 1 | // Check The Sentence includes "Javascriot" init 2 | const check = (str: string): boolean => str.includes("Javascript"); 3 | console.log(check("I Am Learning Javascript")); // True 4 | console.log(check("I Am Learning Tavascript")); // False 5 | -------------------------------------------------------------------------------- /Question-57/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 57:* Find the Average Grade: Given a list of grades, calculate the average grade. 2 | 3 | let grade: number[] = [88, 94, 72, 99, 53, 77]; 4 | let avgGrade = grade.reduce((total, grade) => total + grade, 0) / grade.length; 5 | console.log(avgGrade); 6 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/assert/strict.d.ts: -------------------------------------------------------------------------------- 1 | declare module "assert/strict" { 2 | import { strict } from "node:assert"; 3 | export = strict; 4 | } 5 | declare module "node:assert/strict" { 6 | import { strict } from "node:assert"; 7 | export = strict; 8 | } 9 | -------------------------------------------------------------------------------- /Question-57/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 57:* Find the Average Grade: Given a list of grades, calculate the average grade. 3 | let grade = [88, 94, 72, 99, 53, 77]; 4 | let avgGrade = grade.reduce((total, grade) => total + grade, 0) / grade.length; 5 | console.log(avgGrade); 6 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/interceptors.d.ts: -------------------------------------------------------------------------------- 1 | import Dispatcher from "./dispatcher"; 2 | 3 | type RedirectInterceptorOpts = { maxRedirections?: number } 4 | 5 | export declare function createRedirectInterceptor (opts: RedirectInterceptorOpts): Dispatcher.DispatchInterceptor 6 | -------------------------------------------------------------------------------- /45-Assignment-Q01/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "45-assignment-q1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /45-Assignment-Q08/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | //8. You should create four lines that look like this: 3 | // console.log(5 + 3) 4 | // Your output should simply be four lines with the number 8 appearing once on each line. 5 | console.log(5 + 3); 6 | console.log(16 - 8); 7 | console.log(2 * 4); 8 | console.log(64 / 8); 9 | -------------------------------------------------------------------------------- /45-Assignment-Q08/main.ts: -------------------------------------------------------------------------------- 1 | //8. You should create four lines that look like this: 2 | // console.log(5 + 3) 3 | // Your output should simply be four lines with the number 8 appearing once on each line. 4 | 5 | console.log(5 + 3); 6 | console.log(16 - 8); 7 | console.log(2 * 4); 8 | console.log(64 / 8); 9 | 10 | 11 | -------------------------------------------------------------------------------- /Question-91/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Defines an array with three favorite fruits and push one fruit in it 3 | let favoriteFruits = ["Apple", "Banana", "Cherry"]; 4 | favoriteFruits.push("Mango"); // Adds "Mango" to the end of the array 5 | console.log(favoriteFruits); // Outputs: ['Apple', 'Banana', 'Cherry', 'Mango'] 6 | -------------------------------------------------------------------------------- /Question-91/main.ts: -------------------------------------------------------------------------------- 1 | // Defines an array with three favorite fruits and push one fruit in it 2 | let favoriteFruits: string[] = ["Apple", "Banana", "Cherry"]; 3 | favoriteFruits.push("Mango"); // Adds "Mango" to the end of the array 4 | 5 | console.log(favoriteFruits); // Outputs: ['Apple', 'Banana', 'Cherry', 'Mango'] 6 | -------------------------------------------------------------------------------- /Question-55/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 55:* Double Numbers in an Array: Make a list of numbers. 3 | // Then, use a trick to make a new list where each number is twice its original value. 4 | let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 5 | let doubleNumber = numbers.map(val => val * 2); 6 | console.log(doubleNumber); 7 | -------------------------------------------------------------------------------- /Question-56/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 56:* Keep Only Strings: Given a mix of different types of items, 2 | // make a new list that has only the words. 3 | 4 | let mixedArray = [1, "banana", 2, 3, "apple", 4, "mango", "orange", 5]; 5 | let stringArray = mixedArray.filter(val => typeof val === "string"); 6 | console.log(stringArray); 7 | -------------------------------------------------------------------------------- /Question-86/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | // Check The Sentence includes "Javascriot" init 4 | const check = (str) => str.includes("Javascript"); 5 | console.log(check("I Am Learning Javascript")); // True 6 | console.log(check("I Am Learning Tavascript")); // False 7 | -------------------------------------------------------------------------------- /45-Assignment-Q09/main.js: -------------------------------------------------------------------------------- 1 | // 9. Favorite Number: Store your favorite number in a variable. Then, using that variable, 2 | // create a message that reveals your favorite number. Print that message. 3 | var favoriteNumber = 121; 4 | var message = "My Favorite Number is"; 5 | console.log("".concat(message, " ").concat(favoriteNumber)); 6 | -------------------------------------------------------------------------------- /Question-55/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 55:* Double Numbers in an Array: Make a list of numbers. 2 | // Then, use a trick to make a new list where each number is twice its original value. 3 | 4 | let numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 5 | let doubleNumber: number[] = numbers.map(val => val * 2); 6 | console.log(doubleNumber); 7 | -------------------------------------------------------------------------------- /Question-96/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Make dunction which return the sum of all the number in an array 3 | function calculateSum(arr) { 4 | return arr.reduce((prev, curr) => prev + curr, 0); 5 | } 6 | console.log("The Sum Of All The Number is: ", calculateSum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); // The Sum Of All The Number is: 55 7 | -------------------------------------------------------------------------------- /Question-96/main.ts: -------------------------------------------------------------------------------- 1 | // Make dunction which return the sum of all the number in an array 2 | function calculateSum(arr: number[]): number { 3 | return arr.reduce((prev, curr) => prev + curr, 0); 4 | } 5 | console.log("The Sum Of All The Number is: ", calculateSum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); // The Sum Of All The Number is: 55 6 | -------------------------------------------------------------------------------- /Question-56/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 56:* Keep Only Strings: Given a mix of different types of items, 3 | // make a new list that has only the words. 4 | let mixedArray = [1, "banana", 2, 3, "apple", 4, "mango", "orange", 5]; 5 | let stringArray = mixedArray.filter(val => typeof val === "string"); 6 | console.log(stringArray); 7 | -------------------------------------------------------------------------------- /45-Assignment-Q09/main.ts: -------------------------------------------------------------------------------- 1 | // 9. Favorite Number: Store your favorite number in a variable. Then, using that variable, 2 | // create a message that reveals your favorite number. Print that message. 3 | 4 | let favoriteNumber: number = 121; 5 | let message: string = "My Favorite Number is"; 6 | console.log(`${message} ${favoriteNumber}`); 7 | 8 | -------------------------------------------------------------------------------- /45-Assignment-Q02/main.ts: -------------------------------------------------------------------------------- 1 | // Q2. Personal Message: Store a person’s name in a variable, and print a message to that person. 2 | // Your message should be simple, such as, 3 | // “Hello Eric, would you like to learn some Python today?” 4 | 5 | let name1 : string = "Eric"; 6 | console.log(`Hello ${name1}, "would you like to learn some Python today?"`); -------------------------------------------------------------------------------- /45-Assignment-Q03/main.js: -------------------------------------------------------------------------------- 1 | // Q3 : Name Cases: Store a person’s name in a variable, and then print that person’s name in lowercase, uppercase, and titlecase. 2 | var firstName = "umar farooq"; 3 | console.log(firstName.toLowerCase()); 4 | console.log(firstName.toUpperCase()); 5 | console.log(firstName.charAt(0).toLocaleUpperCase() + firstName.slice(1)); 6 | -------------------------------------------------------------------------------- /45-Assignment-Q02/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 2. Personal Message: Store a person’s name in a variable, and print a message to that person. 3 | // Your message should be simple, such as, 4 | // “Hello Eric, would you like to learn some Python today?” 5 | let name1 = "Eric"; 6 | console.log(`Hello ${name1}, "would you like to learn some Python today?"`); 7 | -------------------------------------------------------------------------------- /Question-84/main.ts: -------------------------------------------------------------------------------- 1 | // Question 84: Replacing Text in a String: 2 | // Write a function that takes a sentence and replaces all instances of the word 3 | // "JavaScript" with "TypeScript". 4 | 5 | function replace(str: string){ 6 | return str.replace(/Javascript/g , "Typescript") 7 | }; 8 | console.log(replace("I Love Javascript , Javascript is Great")); -------------------------------------------------------------------------------- /Question-92/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // make function which removes the last element from an array and returns it 3 | function removeLastElement(arr) { 4 | return arr.pop(); 5 | } 6 | const fruits = ["Apple", "Banana", "Cherry"]; 7 | console.log(removeLastElement(fruits)); // Outputs: 'Cherry' 8 | console.log(fruits); // Outputs: ['Apple', 'Banana'] 9 | -------------------------------------------------------------------------------- /Question-82/index.ts: -------------------------------------------------------------------------------- 1 | // Question 82: Find the Length of a String: 2 | // Write a function that takes a string as an argument and 3 | // returns the number of characters in the string. 4 | 5 | function stringLength(str: string){ 6 | return str.length 7 | }; 8 | let result = stringLength("Umar Farooq"); 9 | console.log(`The Length Of The String is ${result}`); -------------------------------------------------------------------------------- /45-Assignment-Q21/main.js: -------------------------------------------------------------------------------- 1 | // 21. They think of something you could store in a TypeScript Object. Write a program that creates Objects containing these items. 2 | var user = { 3 | firstName: "Umar Farooq", 4 | lastName: "Farooq Jamal", 5 | age: 16, 6 | email: "uhhfj0345@gmail.com", 7 | contact: +923172472531 8 | }; 9 | console.log(user); 10 | -------------------------------------------------------------------------------- /Question-54/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function createObjectWithDynamicKey(key, value) { 3 | let dynamicObject = {}; 4 | // Setting up a section in the list with a changeable name 5 | dynamicObject[key] = value; 6 | return dynamicObject; 7 | } 8 | let userPreference = createObjectWithDynamicKey("theme", "dark"); 9 | console.log(userPreference); 10 | -------------------------------------------------------------------------------- /Question-76/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 76: Function Parameters and Return Values: 3 | // Create a function that takes two numbers as parameters, adds them together, 4 | // and returns the result. Show how you can call this function and log the result. 5 | function addNumbers(num1, num2) { 6 | return num1 + num2; 7 | } 8 | console.log(addNumbers(5, 7)); 9 | -------------------------------------------------------------------------------- /Question-92/main.ts: -------------------------------------------------------------------------------- 1 | // make function which removes the last element from an array and returns it 2 | function removeLastElement(arr: T[]): T | undefined { 3 | return arr.pop(); 4 | } 5 | 6 | const fruits: string[] = ["Apple", "Banana", "Cherry"]; 7 | console.log(removeLastElement(fruits)); // Outputs: 'Cherry' 8 | console.log(fruits); // Outputs: ['Apple', 'Banana'] -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/global-dispatcher.d.ts: -------------------------------------------------------------------------------- 1 | import Dispatcher from "./dispatcher"; 2 | 3 | export { 4 | getGlobalDispatcher, 5 | setGlobalDispatcher 6 | } 7 | 8 | declare function setGlobalDispatcher(dispatcher: DispatcherImplementation): void; 9 | declare function getGlobalDispatcher(): Dispatcher; 10 | -------------------------------------------------------------------------------- /Question-60/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "question-60", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@types/node": "^20.12.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Question-76/main.ts: -------------------------------------------------------------------------------- 1 | // Question 76: Function Parameters and Return Values: 2 | // Create a function that takes two numbers as parameters, adds them together, 3 | // and returns the result. Show how you can call this function and log the result. 4 | 5 | function addNumbers(num1: number, num2: number): number { 6 | return num1 + num2; 7 | } 8 | console.log(addNumbers(5, 7)); -------------------------------------------------------------------------------- /Question-93/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // This function finds "Banana" in the fruits array and replaces it with "Mango" 3 | function replaceBanana(fruits) { 4 | const index = fruits.indexOf("Banana"); 5 | index !== -1 ? fruits[index] = "Mango" : null; 6 | } 7 | const fruits = ["Apple", "Banana", "Cherry"]; 8 | replaceBanana(fruits); 9 | console.log(fruits); 10 | -------------------------------------------------------------------------------- /45-Assignment-Q03/main.ts: -------------------------------------------------------------------------------- 1 | // Q3 : Name Cases: Store a person’s name in a variable, and then print that person’s name in lowercase, uppercase, and titlecase. 2 | 3 | let firstName: string = "umar farooq"; 4 | console.log(firstName.toLowerCase()); 5 | console.log(firstName.toUpperCase()); 6 | console.log(firstName.charAt(0).toUpperCase() + firstName.slice(1).toLowerCase()); 7 | 8 | -------------------------------------------------------------------------------- /Question-70/index.ts: -------------------------------------------------------------------------------- 1 | // Question 70: Understanding let in Loops: 2 | // Write a function that uses a loop with the let keyword to print numbers from 1 to 5. 3 | // Explain how the let keyword affects the visibility of the loop variable. 4 | function printNumbersWithLet() { 5 | for (let i = 1; i <= 5; i++) { 6 | console.log(i); 7 | }; 8 | } 9 | printNumbersWithLet(); -------------------------------------------------------------------------------- /Question-84/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 84: Replacing Text in a String: 3 | // Write a function that takes a sentence and replaces all instances of the word 4 | // "JavaScript" with "TypeScript". 5 | function replace(str) { 6 | return str.replace(/Javascript/g, "Typescript"); 7 | } 8 | ; 9 | console.log(replace("I Love Javascript , Javascript is Great")); 10 | -------------------------------------------------------------------------------- /Question-82/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 82: Find the Length of a String: 3 | // Write a function that takes a string as an argument and 4 | // returns the number of characters in the string. 5 | function stringLength(str) { 6 | return str.length; 7 | } 8 | ; 9 | let result = stringLength("Umar Farooq"); 10 | console.log(`The Length Of The String is ${result}`); 11 | -------------------------------------------------------------------------------- /45-Assignment-Q19/main.js: -------------------------------------------------------------------------------- 1 | // 19. Dinner Guests: Working with one of the programs from Exercises 14 through 18, print a message indicating the number 2 | // of people you are inviting to dinner. 3 | var guestArr = ["Anoosha", "Umar", "Ubaid", "Warisha", "Umaima", "Hamza"]; 4 | var numberOfPeoploes = guestArr.length; 5 | console.log("I Invited ".concat(numberOfPeoploes, " Peoples To a Dinner")); 6 | -------------------------------------------------------------------------------- /Question-68/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 68: Multiplying Decimals: 3 | // Create a function that accepts two decimal numbers and returns their product. 4 | // Round the result to two decimal places. 5 | function multiplyDecimals(num1, num2) { 6 | return Math.round((num1 * num2) * 100) / 100; 7 | } 8 | const result = multiplyDecimals(0.1, 0.2); 9 | console.log(result); 10 | -------------------------------------------------------------------------------- /Question-93/main.ts: -------------------------------------------------------------------------------- 1 | // This function finds "Banana" in the fruits array and replaces it with "Mango" 2 | function replaceBanana(fruits: string[]): void { 3 | const index: number = fruits.indexOf("Banana"); 4 | index !== -1 ? fruits[index] = "Mango" : null; // Condition 5 | } 6 | const fruits: string[] = ["Apple", "Banana", "Cherry"]; 7 | replaceBanana(fruits); 8 | console.log(fruits); 9 | -------------------------------------------------------------------------------- /45-Assignment-Q11/main.js: -------------------------------------------------------------------------------- 1 | // 11. Names: Store the names of a few of your friends in a array called names. 2 | // Print each person’s name by accessing each element in the list, one at a time. 3 | var friends = ["Ubaid", "Hamza", "Subhan", "Huzaifa", "Abdullah"]; 4 | console.log(friends[0]); 5 | console.log(friends[1]); 6 | console.log(friends[2]); 7 | console.log(friends[3]); 8 | console.log(friends[4]); 9 | -------------------------------------------------------------------------------- /45-Assignment-Q19/main.ts: -------------------------------------------------------------------------------- 1 | // 19. Dinner Guests: Working with one of the programs from Exercises 14 through 18, print a message indicating the number 2 | // of people you are inviting to dinner. 3 | 4 | let guestArr: string[] = ["Anoosha","Umar","Ubaid","Warisha","Umaima","Hamza"]; 5 | let numberOfPeoploes: number = guestArr.length; 6 | console.log(`I Invited ${numberOfPeoploes} Peoples To a Dinner`); 7 | -------------------------------------------------------------------------------- /Question-68/index.ts: -------------------------------------------------------------------------------- 1 | // Question 68: Multiplying Decimals: 2 | // Create a function that accepts two decimal numbers and returns their product. 3 | // Round the result to two decimal places. 4 | 5 | function multiplyDecimals(num1: number, num2: number): number { 6 | return Math.round((num1 * num2) * 100) / 100; 7 | } 8 | 9 | const result = multiplyDecimals(0.1, 0.2) 10 | console.log(result); -------------------------------------------------------------------------------- /Question-79/main.ts: -------------------------------------------------------------------------------- 1 | // Question 79: Creating and Accessing Object Properties: 2 | // Construct an object representing a car with properties for make, 3 | // model, and year. Then, show how you can access the model property of the car. 4 | 5 | let car = { 6 | make: "Toyota", 7 | model: "Corolla", 8 | year: 2020 9 | }; 10 | 11 | // Accessing and showing the car's model 12 | console.log(car.model); -------------------------------------------------------------------------------- /45-Assignment-Q11/main.ts: -------------------------------------------------------------------------------- 1 | // 11. Names: Store the names of a few of your friends in a array called names. 2 | // Print each person’s name by accessing each element in the list, one at a time. 3 | 4 | let friends: string[] = ["Ubaid","Hamza","Subhan","Huzaifa","Abdullah"]; 5 | console.log(friends[0]); 6 | console.log(friends[1]); 7 | console.log(friends[2]); 8 | console.log(friends[3]); 9 | console.log(friends[4]); 10 | -------------------------------------------------------------------------------- /45-Assignment-Q20/main.ts: -------------------------------------------------------------------------------- 1 | // 20. Think of something you could store in a array. 2 | // For example, you could make a list of mountains, rivers, countries, cities, languages, or anything 3 | // else you’d like. Write a program that creates a list containing these items. 4 | 5 | let gamesArr: string[] = ["Pubg", "Free fire", "Call of duty", "Valorant", "Fortnite"]; 6 | for (let val of gamesArr) { 7 | console.log(val); 8 | } -------------------------------------------------------------------------------- /Question-70/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 70: Understanding let in Loops: 3 | // Write a function that uses a loop with the let keyword to print numbers from 1 to 5. 4 | // Explain how the let keyword affects the visibility of the loop variable. 5 | function printNumbersWithLet() { 6 | for (let i = 1; i <= 5; i++) { 7 | console.log(i); 8 | } 9 | ; 10 | } 11 | printNumbersWithLet(); 12 | -------------------------------------------------------------------------------- /Question-79/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 79: Creating and Accessing Object Properties: 3 | // Construct an object representing a car with properties for make, 4 | // model, and year. Then, show how you can access the model property of the car. 5 | let car = { 6 | make: "Toyota", 7 | model: "Corolla", 8 | year: 2020 9 | }; 10 | // Accessing and showing the car's model 11 | console.log(car.model); 12 | -------------------------------------------------------------------------------- /45-Assignment-Q05/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Q5. Famous Quote 2: Repeat Exercise 4, but this time store the famous person’s name in a variable called famous_person. 3 | // Then compose your message and store it in a new variable called message. Print your message. 4 | let famous_person = "Hallen Kellar"; 5 | let message = "“Alone we can do so little; together we can do so much”"; 6 | console.log(`${famous_person} said: ${message}`); 7 | -------------------------------------------------------------------------------- /45-Assignment-Q14/main.ts: -------------------------------------------------------------------------------- 1 | // 14. Guest List: If you could invite anyone, living or deceased, to dinner, 2 | // who would you invite? Make a list that includes at least three people you’d like to 3 | // invite to dinner. Then use your list to print a message to each person, inviting them to dinner. 4 | 5 | let guest: string[] = ["Taha","Ayan","Urooj"]; 6 | for(let val of guest){ 7 | console.log(`Dear ${val} I invited You to Dinner`); 8 | } -------------------------------------------------------------------------------- /Question-49/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 49:* Function with Rest Parameters: 2 | // Write a function that takes a rest parameter representing multiple hobbies. 3 | // It should log each hobby with a statement saying you enjoy that hobby. 4 | 5 | function enjoyHobbies(...hobbies: string[]): void { 6 | hobbies.forEach(hobby => { 7 | console.log(`I enjoy ${hobby}`); 8 | }); 9 | } 10 | enjoyHobbies("Gaming","Coding","Helping"); -------------------------------------------------------------------------------- /45-Assignment-Q05/main.ts: -------------------------------------------------------------------------------- 1 | // Q5. Famous Quote 2: Repeat Exercise 4, but this time store the famous person’s name in a variable called famous_person. 2 | // Then compose your message and store it in a new variable called message. Print your message. 3 | 4 | let famous_person: string = "Hallen Kellar"; 5 | let message: string = "“Alone we can do so little; together we can do so much”"; 6 | console.log(`${famous_person} said: ${message}`); 7 | 8 | -------------------------------------------------------------------------------- /Question-49/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 49:* Function with Rest Parameters: 3 | // Write a function that takes a rest parameter representing multiple hobbies. 4 | // It should log each hobby with a statement saying you enjoy that hobby. 5 | function enjoyHobbies(...hobbies) { 6 | hobbies.forEach(hobby => { 7 | console.log(`I enjoy ${hobby}`); 8 | }); 9 | } 10 | enjoyHobbies("Gaming", "Coding", "Helping"); 11 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/mock-errors.d.ts: -------------------------------------------------------------------------------- 1 | import Errors from './errors' 2 | 3 | export default MockErrors 4 | 5 | declare namespace MockErrors { 6 | /** The request does not match any registered mock dispatches. */ 7 | export class MockNotMatchedError extends Errors.UndiciError { 8 | constructor(message?: string); 9 | name: 'MockNotMatchedError'; 10 | code: 'UND_MOCK_ERR_MOCK_NOT_MATCHED'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Question-63/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Describing a circle using our Shape type 3 | let circle = { 4 | kind: "circle", 5 | radius: 5 6 | }; 7 | // Describing a rectangle using our Shape type 8 | let rectangle = { 9 | kind: "rectangle", 10 | width: 10, 11 | height: 20 12 | }; 13 | // Showing what we described 14 | console.log(circle); // Here's the circle 15 | console.log(rectangle); // And here's the rectangle 16 | -------------------------------------------------------------------------------- /Question-65/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 65: Determine the Remainder: 3 | // Make a function that gets two numbers and shows the leftover 4 | // from dividing them using the % sign. For example, remainder(5, 2) should give 1. 5 | function remainder(num1, num2) { 6 | return num1 % num2; 7 | } 8 | // Test the function 9 | const result = remainder(5, 2); 10 | console.log(`The remainder of 5 divided by 2 is: ${result}`); 11 | -------------------------------------------------------------------------------- /Question-98/main.ts: -------------------------------------------------------------------------------- 1 | // Calculates how many days are left until New Year's Day 2 | function calculateDays(): number { 3 | const today = new Date(); 4 | const newYear = new Date(today.getFullYear() + 1, 1, 0); 5 | const diff = newYear.getTime() - today.getTime(); 6 | const days = Math.ceil(diff / (1000 * 60 * 60 * 24)); 7 | return days; 8 | } 9 | console.log(`There are ${calculateDays()} Days Left in a New Year`); 10 | -------------------------------------------------------------------------------- /Question-48/index.ts: -------------------------------------------------------------------------------- 1 | // Combining Arrays with Spread Operator: Suppose you're comparing prices of two different sets 2 | // of laptops. Use the spread operator to combine these arrays into a single array sorted in 3 | // ascending order, then log the result. 4 | 5 | let pricesSet1 = [1200, 1500, 1100]; 6 | let pricesSet2 = [1000, 1300, 1600]; 7 | let combinedPrices = [...pricesSet1, ...pricesSet2].sort((a, b) => a - b); 8 | console.log(combinedPrices); -------------------------------------------------------------------------------- /45-Assignment-Q41/main.js: -------------------------------------------------------------------------------- 1 | // 41. Magicians: Make a array of magician’s names. Pass the array to a function 2 | // called show_magicians(), which prints the name of each magician in the array. 3 | var magicians = ["Merlin", "Houdini", "David Copperfield", "Penn & Teller"]; 4 | function show_magicians(magicians) { 5 | magicians.forEach(function (magician) { 6 | console.log(magician); 7 | }); 8 | } 9 | show_magicians(magicians); 10 | -------------------------------------------------------------------------------- /Question-51/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 51:* Refactoring to Arrow Functions: 3 | // Take a simple function that calculates the area of a rectangle and 4 | // refactor it into an arrow function. 5 | function calculateArea(width, height) { 6 | return width * height; 7 | } 8 | let areaOfReactangle = (length, width) => { 9 | return length * width; 10 | }; 11 | console.log(`The Area Of Reactangle is ${areaOfReactangle(5, 9)}`); 12 | -------------------------------------------------------------------------------- /Question-98/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Calculates how many days are left until New Year's Day 3 | function calculateDays() { 4 | const today = new Date(); 5 | const newYear = new Date(today.getFullYear() + 1, 1, 0); 6 | const diff = newYear.getTime() - today.getTime(); 7 | const days = Math.ceil(diff / (1000 * 60 * 60 * 24)); 8 | return days; 9 | } 10 | console.log(`There are ${calculateDays()} Days Left in a New Year`); 11 | -------------------------------------------------------------------------------- /Question-64/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 64: Combine Strings and Numbers: 3 | // Write a function that merges a piece of text with a number. 4 | // For example, if provided with "Age: " and 30, it should give back "Age: 30". 5 | function combineTextAndNumber(text, number) { 6 | return text + number.toString(); 7 | } 8 | // Example usage 9 | const result = combineTextAndNumber("Age: ", 30); 10 | console.log(result); // Output: "Age: 30" 11 | -------------------------------------------------------------------------------- /Question-65/index.ts: -------------------------------------------------------------------------------- 1 | // Question 65: Determine the Remainder: 2 | // Make a function that gets two numbers and shows the leftover 3 | // from dividing them using the % sign. For example, remainder(5, 2) should give 1. 4 | 5 | function remainder(num1: number, num2: number): number { 6 | return num1 % num2; 7 | } 8 | 9 | // Test the function 10 | 11 | const result = remainder(5, 2); 12 | console.log(`The remainder of 5 divided by 2 is: ${result}`); -------------------------------------------------------------------------------- /Question-46/index.ts: -------------------------------------------------------------------------------- 1 | // Question 46: Enhanced Laptop Object: Construct an object for a laptop including properties make, 2 | // model, year, and a method describe() that logs a sentence about the laptop. 3 | 4 | let laptop = { 5 | make: "Dell", 6 | model: "XPS 15", 7 | year: 2021, 8 | describe: function() { 9 | console.log(`This laptop is a ${laptop.year} ${laptop.make} ${laptop.model}.`); 10 | } 11 | }; 12 | laptop.describe(); -------------------------------------------------------------------------------- /Question-67/index.ts: -------------------------------------------------------------------------------- 1 | // Question 67: Arithmetic with Mixed Types: 2 | // Write a function that takes two parameters: 3 | // a number and a string that represents a number (e.g., "5"). 4 | // Return their sum as a number. 5 | 6 | import { log } from "console"; 7 | 8 | function arithmeticMixedType(value1: number, value2: string) { 9 | return value1 + Number(value2); 10 | } 11 | const result = arithmeticMixedType(5,"10"); 12 | console.log(result); 13 | -------------------------------------------------------------------------------- /Question-83/main.ts: -------------------------------------------------------------------------------- 1 | // Question 83: Converting to Upper and Lower Case: 2 | // Create a function that takes a string, converts it to uppercase, 3 | // then to lowercase, and logs both. 4 | 5 | import { log } from "console"; 6 | 7 | function convert(str: string) { 8 | let upperCase = str.toUpperCase(); 9 | let lowerCase = str.toLowerCase(); 10 | console.log(`UpperCase : ${upperCase}\nLowerCase : ${lowerCase}`); 11 | }; 12 | convert("Umar Farooq") -------------------------------------------------------------------------------- /Question-48/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Combining Arrays with Spread Operator: Suppose you're comparing prices of two different sets 3 | // of laptops. Use the spread operator to combine these arrays into a single array sorted in 4 | // ascending order, then log the result. 5 | let pricesSet1 = [1200, 1500, 1100]; 6 | let pricesSet2 = [1000, 1300, 1600]; 7 | let combinedPrices = [...pricesSet1, ...pricesSet2].sort((a, b) => a - b); 8 | console.log(combinedPrices); 9 | -------------------------------------------------------------------------------- /Question-64/index.ts: -------------------------------------------------------------------------------- 1 | // Question 64: Combine Strings and Numbers: 2 | // Write a function that merges a piece of text with a number. 3 | // For example, if provided with "Age: " and 30, it should give back "Age: 30". 4 | 5 | function combineTextAndNumber(text: string, number: number): string { 6 | return text + number.toString(); 7 | } 8 | 9 | // Example usage 10 | const result = combineTextAndNumber("Age: ", 30); 11 | console.log(result); // Output: "Age: 30" -------------------------------------------------------------------------------- /45-Assignment-Q41/main.ts: -------------------------------------------------------------------------------- 1 | // 41. Magicians: Make a array of magician’s names. Pass the array to a function 2 | // called show_magicians(), which prints the name of each magician in the array. 3 | 4 | let magicians: string[] = ["Merlin", "Houdini", "David Copperfield", "Penn & Teller"]; 5 | function show_magicians(magicians: string[]) { 6 | magicians.forEach(function (magician) { 7 | console.log(magician); 8 | }); 9 | } 10 | show_magicians(magicians); -------------------------------------------------------------------------------- /Question-77/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 77: Default Parameters: Write a function that greets a user. 3 | // It should take the user's name as a parameter and say hello. 4 | // If no name is given, it should greet an anonymous user. 5 | function greetUser(name = "anonymous") { 6 | // Says hello to the given name or to an anonymous user 7 | console.log(`Hello, ${name}!`); 8 | } 9 | greetUser("Alice"); // Outputs: Hello, Alice! 10 | greetUser(); 11 | -------------------------------------------------------------------------------- /45-Assignment-Q04/main.ts: -------------------------------------------------------------------------------- 1 | // Q4. Famous Quote: Find a quote from a famous person you admire. 2 | // Print the quote and the name of its author. Your output should look something like the 3 | // following, including the quotation marks: 4 | // Albert Einstein once said, “A person who never made a mistake never tried anything new.” 5 | 6 | let personName: string = ("Hallen Keller said:"); 7 | console.log(`${personName} “Alone we can do so little; together we can do so much”`); 8 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/handlers.d.ts: -------------------------------------------------------------------------------- 1 | import Dispatcher from "./dispatcher"; 2 | 3 | export declare class RedirectHandler implements Dispatcher.DispatchHandlers{ 4 | constructor (dispatch: Dispatcher, maxRedirections: number, opts: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers) 5 | } 6 | 7 | export declare class DecoratorHandler implements Dispatcher.DispatchHandlers{ 8 | constructor (handler: Dispatcher.DispatchHandlers) 9 | } 10 | -------------------------------------------------------------------------------- /45-Assignment-Q04/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Q4. Famous Quote: Find a quote from a famous person you admire. 3 | // Print the quote and the name of its author. Your output should look something like the 4 | // following, including the quotation marks: 5 | // Albert Einstein once said, “A person who never made a mistake never tried anything new.” 6 | let personName = ("Hallen Keller said:"); 7 | console.log(`${personName} “Alone we can do so little; together we can do so much”`); 8 | -------------------------------------------------------------------------------- /Question-46/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 46: Enhanced Laptop Object: Construct an object for a laptop including properties make, 3 | // model, year, and a method describe() that logs a sentence about the laptop. 4 | let laptop = { 5 | make: "Dell", 6 | model: "XPS 15", 7 | year: 2021, 8 | describe: function () { 9 | console.log(`This laptop is a ${laptop.year} ${laptop.make} ${laptop.model}.`); 10 | } 11 | }; 12 | laptop.describe(); 13 | -------------------------------------------------------------------------------- /Question-67/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 67: Arithmetic with Mixed Types: 3 | // Write a function that takes two parameters: 4 | // a number and a string that represents a number (e.g., "5"). 5 | // Return their sum as a number. 6 | Object.defineProperty(exports, "__esModule", { value: true }); 7 | function arithmeticMixedType(value1, value2) { 8 | return value1 + Number(value2); 9 | } 10 | const result = arithmeticMixedType(5, "10"); 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /Question-97/main.ts: -------------------------------------------------------------------------------- 1 | // This function formats the current date as DD-MM-YYYY 2 | function getCurrentDateFormatted(): void { 3 | const now = new Date(); 4 | const day = String(now.getDate()).padStart(2, "0"); // Ensures the day is two digits 5 | const month = String(now.getMonth() + 1).padStart(2, "0"); // Adds 1 because months are 0-indexed 6 | const year = now.getFullYear(); 7 | console.log(`${day}-${month}-${year}`); 8 | 9 | } 10 | getCurrentDateFormatted(); -------------------------------------------------------------------------------- /45-Assignment-Q20/main.js: -------------------------------------------------------------------------------- 1 | // 20. Think of something you could store in a array. 2 | // For example, you could make a list of mountains, rivers, countries, cities, languages, or anything 3 | // else you’d like. Write a program that creates a list containing these items. 4 | var gamesArr = ["Pubg", "Free fire", "Call of duty", "Valorant", "Fortnite"]; 5 | for (var _i = 0, gamesArr_1 = gamesArr; _i < gamesArr_1.length; _i++) { 6 | var val = gamesArr_1[_i]; 7 | console.log(val); 8 | } 9 | -------------------------------------------------------------------------------- /Question-51/main.ts: -------------------------------------------------------------------------------- 1 | // Question 51:* Refactoring to Arrow Functions: 2 | // Take a simple function that calculates the area of a rectangle and 3 | // refactor it into an arrow function. 4 | 5 | function calculateArea(width: number, height: number): number { 6 | return width * height; 7 | } 8 | 9 | let areaOfReactangle = (length: number, width: number) => { 10 | return length * width; 11 | } 12 | 13 | console.log(`The Area Of Reactangle is ${areaOfReactangle(5, 9)}`); 14 | -------------------------------------------------------------------------------- /Question-58/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 58:* Average Score Calculator: 3 | // Write a simple program that can take lots of scores and find their average. 4 | function averageScore(scores) { 5 | let sum = 0; 6 | for (const score of scores) { 7 | sum += score; 8 | } 9 | return sum / scores.length; 10 | } 11 | const sampleScores = [80, 77, 88, 95, 68]; 12 | const average = averageScore(sampleScores); 13 | console.log(`Average score: ${average}`); 14 | -------------------------------------------------------------------------------- /45-Assignment-Q36/main.js: -------------------------------------------------------------------------------- 1 | // 36. T-Shirt: Write a function called make_shirt() that accepts a size and the 2 | // text of a message that should be printed on the shirt. The function should print 3 | // a sentence summarizing the size of the shirt and the message printed on it. 4 | // Call the function. 5 | function make_shirt(size, message) { 6 | console.log("\"You ordered a ".concat(size, " shirt with the message:\" ").concat(message)); 7 | } 8 | make_shirt("Medium", "I love coding!"); 9 | -------------------------------------------------------------------------------- /45-Assignment-Q36/main.ts: -------------------------------------------------------------------------------- 1 | // 36. T-Shirt: Write a function called make_shirt() that accepts a size and the 2 | // text of a message that should be printed on the shirt. The function should print 3 | // a sentence summarizing the size of the shirt and the message printed on it. 4 | // Call the function. 5 | 6 | function make_shirt(size: string, message: string): void { 7 | console.log(`"You ordered a ${size} shirt with the message:" ${message}`); 8 | } 9 | make_shirt("Medium", "I love coding!"); -------------------------------------------------------------------------------- /Question-58/index.ts: -------------------------------------------------------------------------------- 1 | // *Question 58:* Average Score Calculator: 2 | // Write a simple program that can take lots of scores and find their average. 3 | 4 | function averageScore(scores: number[]): number { 5 | let sum = 0; 6 | for (const score of scores) { 7 | sum += score; 8 | } 9 | return sum / scores.length; 10 | } 11 | 12 | const sampleScores = [80, 77, 88, 95, 68]; 13 | const average = averageScore(sampleScores); 14 | console.log(`Average score: ${average}`); -------------------------------------------------------------------------------- /Question-77/main.ts: -------------------------------------------------------------------------------- 1 | // Question 77: Default Parameters: Write a function that greets a user. 2 | // It should take the user's name as a parameter and say hello. 3 | // If no name is given, it should greet an anonymous user. 4 | 5 | function greetUser(name: string = "anonymous") { 6 | // Says hello to the given name or to an anonymous user 7 | console.log(`Hello, ${name}!`); 8 | } 9 | 10 | greetUser("Alice"); // Outputs: Hello, Alice! 11 | greetUser(); // Outputs: Hello, anonymous -------------------------------------------------------------------------------- /Question-97/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // This function formats the current date as DD-MM-YYYY 3 | function getCurrentDateFormatted() { 4 | const now = new Date(); 5 | const day = String(now.getDate()).padStart(2, "0"); // Ensures the day is two digits 6 | const month = String(now.getMonth() + 1).padStart(2, "0"); // Adds 1 because months are 0-indexed 7 | const year = now.getFullYear(); 8 | console.log(`${day}-${month}-${year}`); 9 | } 10 | getCurrentDateFormatted(); 11 | -------------------------------------------------------------------------------- /Question-66/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 66: Logical AND Verification: 3 | // Create a function that checks two boolean (true or false) values. 4 | // It should only say true if both are true, using the && operator. 5 | // For instance, checkBothTrue(true, false) should be false. 6 | function checkBothTrue(value1, value2) { 7 | return value1 && value2; 8 | } 9 | // Test the function 10 | const result = checkBothTrue(true, false); 11 | console.log(`Result: ${result}`); // Output: false 12 | -------------------------------------------------------------------------------- /Question-83/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 83: Converting to Upper and Lower Case: 3 | // Create a function that takes a string, converts it to uppercase, 4 | // then to lowercase, and logs both. 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | function convert(str) { 7 | let upperCase = str.toUpperCase(); 8 | let lowerCase = str.toLowerCase(); 9 | console.log(`UpperCase : ${upperCase}\nLowerCase : ${lowerCase}`); 10 | } 11 | ; 12 | convert("Umar Farooq"); 13 | -------------------------------------------------------------------------------- /45-Assignment-Q14/main.js: -------------------------------------------------------------------------------- 1 | // 14. Guest List: If you could invite anyone, living or deceased, to dinner, 2 | // who would you invite? Make a list that includes at least three people you’d like to 3 | // invite to dinner. Then use your list to print a message to each person, inviting them to dinner. 4 | var guest = ["Taha", "Ayan", "Urooj"]; 5 | for (var _i = 0, guest_1 = guest; _i < guest_1.length; _i++) { 6 | var val = guest_1[_i]; 7 | console.log("Dear ".concat(val, " I invited You to Dinner")); 8 | } 9 | -------------------------------------------------------------------------------- /45-Assignment-Q13/main.ts: -------------------------------------------------------------------------------- 1 | // 13. Your Own Array: Think of your favorite mode of transportation, such as a motorcycle or a car, 2 | // and make a list that stores several examples. Use your list 3 | // to print a series of statements about these items, such as “I would like to own a Honda motorcycle.” 4 | 5 | let transportation: string[] = ["Honda Bike", "Carrola Car"]; 6 | let statements: string = "I would like to own a"; 7 | for (let val of transportation){ 8 | console.log(`${statements} ${val}`); 9 | } 10 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/README.md: -------------------------------------------------------------------------------- 1 | # undici-types 2 | 3 | This package is a dual-publish of the [undici](https://www.npmjs.com/package/undici) library types. The `undici` package **still contains types**. This package is for users who _only_ need undici types (such as for `@types/node`). It is published alongside every release of `undici`, so you can always use the same version. 4 | 5 | - [GitHub nodejs/undici](https://github.com/nodejs/undici) 6 | - [Undici Documentation](https://undici.nodejs.org/#/) 7 | -------------------------------------------------------------------------------- /Question-66/index.ts: -------------------------------------------------------------------------------- 1 | // Question 66: Logical AND Verification: 2 | // Create a function that checks two boolean (true or false) values. 3 | // It should only say true if both are true, using the && operator. 4 | // For instance, checkBothTrue(true, false) should be false. 5 | function checkBothTrue(value1: boolean, value2: boolean): boolean { 6 | return value1 && value2; 7 | } 8 | 9 | // Test the function 10 | const result = checkBothTrue(true, false); 11 | console.log(`Result: ${result}`); // Output: false -------------------------------------------------------------------------------- /45-Assignment-Q40/main.js: -------------------------------------------------------------------------------- 1 | function make_album(artist, title, tracks) { 2 | var album = { 3 | artist: artist, 4 | title: title, 5 | }; 6 | if (tracks) { 7 | album.tracks = tracks; 8 | } 9 | return album; 10 | } 11 | var album1 = make_album("The Beatles", "Abbey Road"); 12 | console.log(album1); 13 | var album2 = make_album("Michael Jackson", "Thriller"); 14 | console.log(album2); 15 | var album3 = make_album("Queen", "A Night at the Opera", 14); 16 | console.log(album3); 17 | -------------------------------------------------------------------------------- /Question-99/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Generates a Date object for the next occurrence of a specific birthday 3 | function getBirthday(month, day) { 4 | let today = new Date(); 5 | let year = today.getFullYear(); 6 | const birthday = new Date(year, month - 1, day); 7 | if (birthday < today) { 8 | birthday.setFullYear(year + 1); 9 | } 10 | return birthday; 11 | } 12 | const nextBirthday = getBirthday(8, 19); 13 | console.log("Next birthday on:", nextBirthday.toLocaleDateString()); 14 | -------------------------------------------------------------------------------- /Question-99/main.ts: -------------------------------------------------------------------------------- 1 | // Generates a Date object for the next occurrence of a specific birthday 2 | function getBirthday(month: number, day: number): Date { 3 | let today = new Date(); 4 | let year = today.getFullYear(); 5 | const birthday = new Date(year, month - 1, day); 6 | if (birthday < today) { 7 | birthday.setFullYear(year + 1); 8 | } 9 | return birthday; 10 | } 11 | 12 | const nextBirthday = getBirthday(8, 19); 13 | console.log("Next birthday on:", nextBirthday.toLocaleDateString()); -------------------------------------------------------------------------------- /45-Assignment-Q21/main.ts: -------------------------------------------------------------------------------- 1 | // 21. They think of something you could store in a TypeScript Object. Write a program that creates Objects containing these items. 2 | 3 | type person = { 4 | firstName: string, 5 | lastName: string, 6 | age: number, 7 | email: string, 8 | contact: number, 9 | } 10 | let user: person = { 11 | firstName: "Umar Farooq", 12 | lastName: "Farooq Jamal", 13 | age: 16, 14 | email: "uhhfj0345@gmail.com", 15 | contact: 923172472531 16 | } 17 | console.log(user); 18 | -------------------------------------------------------------------------------- /45-Assignment-Q31/main.js: -------------------------------------------------------------------------------- 1 | // 31. No Users: Add an if test to Exercise 28 to make sure the list of users is not empty. 2 | // • If the list is empty, print the message We need to find some users! 3 | // • Remove all of the usernames from your array, and make sure the correct message is printed. 4 | var users = ["eric", "john", "admin", "bob", "ever"]; 5 | users = []; 6 | if (users.length === 0) { 7 | console.log("We need to find some users!"); 8 | } 9 | else { 10 | console.log("All usernames have been removed"); 11 | } 12 | -------------------------------------------------------------------------------- /Question-52/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 52:* Make a Smartphone Object: 2 | // Create a simple way to keep track of a smartphone's details. 3 | // Include its brand, model, and other key features like how much storage it has, 4 | // the size of its screen, and how long its battery lasts. 5 | 6 | let smartphone = { 7 | make: "Samsung", 8 | model: "Galaxy S21", 9 | specs: { 10 | storage: "128GB", 11 | screenSize: "6.2 inches", 12 | batteryLife: "18 hours" 13 | } 14 | }; 15 | console.log(smartphone); 16 | -------------------------------------------------------------------------------- /Question-80/main.ts: -------------------------------------------------------------------------------- 1 | // Question 80: Updating Object Properties: 2 | // Add a property named color to the existing car object, 3 | // and then update the year property to 2021. 4 | // Show how to perform these operations. 5 | let car = { 6 | make: "Toyota", 7 | model: "Corolla", 8 | year: 2020 9 | }; 10 | // Adding a new property 'color' and updating 'year' 11 | car.color = "blue"; // Adds a new property 'color' 12 | car.year = 2021; // Updates the 'year' property 13 | // Showing the updated car object 14 | console.log(car); -------------------------------------------------------------------------------- /45-Assignment-Q31/main.ts: -------------------------------------------------------------------------------- 1 | // 31. No Users: Add an if test to Exercise 28 to make sure the list of users is not empty. 2 | // • If the list is empty, print the message We need to find some users! 3 | // • Remove all of the usernames from your array, and make sure the correct message is printed. 4 | 5 | let users: string[] = ["eric", "john", "admin", "bob", "ever"]; 6 | 7 | users = []; 8 | 9 | if (users.length === 0) { 10 | console.log("We need to find some users!"); 11 | } else { 12 | console.log("All usernames have been removed"); 13 | } -------------------------------------------------------------------------------- /Question-52/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 52:* Make a Smartphone Object: 3 | // Create a simple way to keep track of a smartphone's details. 4 | // Include its brand, model, and other key features like how much storage it has, 5 | // the size of its screen, and how long its battery lasts. 6 | let smartphone = { 7 | make: "Samsung", 8 | model: "Galaxy S21", 9 | specs: { 10 | storage: "128GB", 11 | screenSize: "6.2 inches", 12 | batteryLife: "18 hours" 13 | } 14 | }; 15 | console.log(smartphone); 16 | -------------------------------------------------------------------------------- /45-Assignment-Q06/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Q6. Stripping Names: Store a person’s name, and include some whitespace characters 3 | // at the beginning and end of the name. Make sure you use each 4 | // character combination, "\t" and "\n", at least once. Print the name once, 5 | // so the whitespace around the name is displayed. Then print the name after striping the white spaces. 6 | let pName = "UmarFarooq"; 7 | console.log(pName); 8 | let prName = "Umar\tFarooq"; 9 | console.log(prName); 10 | let prsName = "Umar\nFarooq"; 11 | console.log(prsName); 12 | -------------------------------------------------------------------------------- /Question-80/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 80: Updating Object Properties: 3 | // Add a property named color to the existing car object, 4 | // and then update the year property to 2021. 5 | // Show how to perform these operations. 6 | let car = { 7 | make: "Toyota", 8 | model: "Corolla", 9 | year: 2020 10 | }; 11 | // Adding a new property 'color' and updating 'year' 12 | car.color = "blue"; // Adds a new property 'color' 13 | car.year = 2021; // Updates the 'year' property 14 | // Showing the updated car object 15 | console.log(car); 16 | -------------------------------------------------------------------------------- /Question-59/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 59:* Add a Special Number: Make a program that creates custom adders. 3 | // These adders can add a specific number to any other number you give them later. 4 | function addSpecialNumber(specialNumber) { 5 | if (typeof specialNumber !== 'number') { 6 | throw new Error('Expected a number for the special number'); 7 | } 8 | return (n) => { 9 | return n + specialNumber; 10 | }; 11 | } 12 | const adderThatAdds5 = addSpecialNumber(5); 13 | console.log(adderThatAdds5(3)); // Output: 8 14 | -------------------------------------------------------------------------------- /45-Assignment-Q06/main.ts: -------------------------------------------------------------------------------- 1 | // Q6. Stripping Names: Store a person’s name, and include some whitespace characters 2 | // at the beginning and end of the name. Make sure you use each 3 | // character combination, "\t" and "\n", at least once. Print the name once, 4 | // so the whitespace around the name is displayed. Then print the name after striping the white spaces. 5 | 6 | let pName: string = "UmarFarooq"; 7 | console.log(pName); 8 | let prName: string = "Umar\tFarooq"; 9 | console.log(prName); 10 | let prsName: string = "Umar\nFarooq"; 11 | console.log(prsName); 12 | -------------------------------------------------------------------------------- /Question-78/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 78: Function Expressions vs. Function Declarations: 3 | // Compare function expressions and declarations by creating one of each 4 | // that performs the same task, such as squaring a number. 5 | function squareDeclaration(number) { 6 | return number * number; 7 | } 8 | // Function expression for squaring a number 9 | const squareExpression = function (number) { 10 | return number * number; 11 | }; 12 | console.log(squareDeclaration(4)); // Outputs: 16 13 | console.log(squareExpression(4)); // Outputs: 16 14 | -------------------------------------------------------------------------------- /45-Assignment-Q22/main.js: -------------------------------------------------------------------------------- 1 | // 22. Intentional Error: If you haven’t received an array index error in one of your programs yet, 2 | // try to make one happen. Change an index in one of your programs 3 | // to produce an index error. Make sure you correct the error before closing the program. 4 | var skills = ["HTML", "CSS", "BOOTSTRAP", "JAVASCRIPT", "TYPESCRIPT"]; 5 | // Intentional Error : Not Found The Index Of The Array 6 | // Because Array Started With index of 0 so skills[5] is undefined. 7 | console.log(skills[5]); 8 | // Error Correcting 9 | console.log(skills[4]); 10 | -------------------------------------------------------------------------------- /Question-61/index.ts: -------------------------------------------------------------------------------- 1 | // *Question 61:* Making Enums for Vehicles: 2 | // Let's create categories for vehicles like cars, trucks, and motorcycles using enums, 3 | // and show one example. 4 | 5 | enum Vehicle { 6 | Car = 'CAR', 7 | Truck = 'TRUCK', 8 | Motorcycle = 'MOTORCYCLE' 9 | } 10 | function isCar(vehicle: Vehicle) { 11 | return vehicle === Vehicle.Car; 12 | } 13 | // Usage 14 | let vehicleType: Vehicle = Vehicle.Car; 15 | 16 | if (isCar(vehicleType)) { 17 | console.log('This is a car'); 18 | } else { 19 | console.log('This is not a car'); 20 | } -------------------------------------------------------------------------------- /Question-71/index.ts: -------------------------------------------------------------------------------- 1 | // Question 71: Compare let and const: 2 | // Create two examples where let allows reassignment but const does not. 3 | // Try to reassign a const-declared variable and catch the error. 4 | 5 | let age = 25; 6 | age = 26; // Works fine because `let` allows reassignment 7 | console.log(age); // Shows 26 8 | 9 | // Trying to reassign a `const`-declared variable 10 | const name = "Alice"; 11 | try { 12 | name = "Bob"; // This line will cause an error 13 | } catch (error) { 14 | console.log("Error: Can't reassign a `const`-declared variable."); 15 | } -------------------------------------------------------------------------------- /Question-78/main.ts: -------------------------------------------------------------------------------- 1 | // Question 78: Function Expressions vs. Function Declarations: 2 | // Compare function expressions and declarations by creating one of each 3 | // that performs the same task, such as squaring a number. 4 | 5 | function squareDeclaration(number: number): number { 6 | return number * number; 7 | } 8 | // Function expression for squaring a number 9 | const squareExpression = function(number: number): number { 10 | return number * number; 11 | }; 12 | console.log(squareDeclaration(4)); // Outputs: 16 13 | console.log(squareExpression(4)); // Outputs: 16 -------------------------------------------------------------------------------- /Question-81/main.ts: -------------------------------------------------------------------------------- 1 | // Question 81: Iterating Over Object Properties: 2 | // Write a function that takes an object as an argument and logs all of 3 | // its properties and values. 4 | 5 | function logObjectProperties(obj: any) { 6 | for (let property in obj) { 7 | // Loops through each property in the object 8 | console.log(`${property}: ${obj[property]}`); 9 | // Shows the property name and its value 10 | } 11 | } 12 | 13 | // Using the function with a car object 14 | logObjectProperties({ make: "Toyota", model: "Corolla", year: 2021, color: "blue" }); -------------------------------------------------------------------------------- /45-Assignment-Q22/main.ts: -------------------------------------------------------------------------------- 1 | // 22. Intentional Error: If you haven’t received an array index error in one of your programs yet, 2 | // try to make one happen. Change an index in one of your programs 3 | // to produce an index error. Make sure you correct the error before closing the program. 4 | 5 | let skills: string[] = ["HTML","CSS","BOOTSTRAP","JAVASCRIPT","TYPESCRIPT"]; 6 | // Intentional Error : Not Found The Index Of The Array 7 | // Because Array Started With index of 0 so skills[5] is undefined. 8 | console.log(skills[5]); 9 | // Error Correcting 10 | console.log(skills[4]); 11 | -------------------------------------------------------------------------------- /Question-73/main.ts: -------------------------------------------------------------------------------- 1 | // Question 73: Assigning and Updating Variables: 2 | // Create a function where you declare a variable using let and assign an initial value. 3 | // Then, update its value within the same function and log both the initial and updated values. 4 | 5 | function updateVariable() { 6 | let number = 10; // Initially assigns the value 10 7 | console.log("Initial value:", number); // Logs the initial value 8 | 9 | number = 20; // Updates the value to 20 10 | console.log("Updated value:", number); // Logs the updated value 11 | } 12 | 13 | updateVariable(); -------------------------------------------------------------------------------- /45-Assignment-Q39/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 39. City Names: Write a function called city_country() that takes in the name 3 | // of a city and its country. The function should return a string formatted like this: 4 | // "Lahore, Pakistan" 5 | // Call your function with at least three city-country pairs, and print the value 6 | // that’s returned. 7 | function city_country(city, country) { 8 | return city.concat(", " + country); 9 | } 10 | console.log(city_country("Lahore", "Pakistan")); 11 | console.log(city_country("Tokyo", "Japan")); 12 | console.log(city_country("Paris", "France")); 13 | -------------------------------------------------------------------------------- /Question-69/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 69: Dividing and Finding the Remainder: 3 | // Write a function that divides two numbers and returns both the quotient 4 | // and the remainder. Use an object to return both values. 5 | // This function divides two numbers and finds the quotient and remainder 6 | function divideAndRemainder(dividend, divisor) { 7 | let quotient = Math.floor(dividend / divisor); 8 | let remainder = dividend % divisor; 9 | return { quotient, remainder }; 10 | } 11 | console.log(divideAndRemainder(10, 3)); // Shows { quotient: 3, remainder: 1 } 12 | -------------------------------------------------------------------------------- /Question-71/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 71: Compare let and const: 3 | // Create two examples where let allows reassignment but const does not. 4 | // Try to reassign a const-declared variable and catch the error. 5 | let age = 25; 6 | age = 26; // Works fine because `let` allows reassignment 7 | console.log(age); // Shows 26 8 | // Trying to reassign a `const`-declared variable 9 | const name = "Alice"; 10 | try { 11 | name = "Bob"; // This line will cause an error 12 | } 13 | catch (error) { 14 | console.log("Error: Can't reassign a `const`-declared variable."); 15 | } 16 | -------------------------------------------------------------------------------- /Question-73/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 73: Assigning and Updating Variables: 3 | // Create a function where you declare a variable using let and assign an initial value. 4 | // Then, update its value within the same function and log both the initial and updated values. 5 | function updateVariable() { 6 | let number = 10; // Initially assigns the value 10 7 | console.log("Initial value:", number); // Logs the initial value 8 | number = 20; // Updates the value to 20 9 | console.log("Updated value:", number); // Logs the updated value 10 | } 11 | updateVariable(); 12 | -------------------------------------------------------------------------------- /Question-81/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 81: Iterating Over Object Properties: 3 | // Write a function that takes an object as an argument and logs all of 4 | // its properties and values. 5 | function logObjectProperties(obj) { 6 | for (let property in obj) { 7 | // Loops through each property in the object 8 | console.log(`${property}: ${obj[property]}`); 9 | // Shows the property name and its value 10 | } 11 | } 12 | // Using the function with a car object 13 | logObjectProperties({ make: "Toyota", model: "Corolla", year: 2021, color: "blue" }); 14 | -------------------------------------------------------------------------------- /45-Assignment-Q13/main.js: -------------------------------------------------------------------------------- 1 | // 13. Your Own Array: Think of your favorite mode of transportation, such as a motorcycle or a car, 2 | // and make a list that stores several examples. Use your list 3 | // to print a series of statements about these items, such as “I would like to own a Honda motorcycle.” 4 | var transportation = ["Honda Bike", "Carrola Car"]; 5 | var statements = "I would like to own a"; 6 | for (var _i = 0, transportation_1 = transportation; _i < transportation_1.length; _i++) { 7 | var val = transportation_1[_i]; 8 | console.log("".concat(statements, " ").concat(val)); 9 | } 10 | -------------------------------------------------------------------------------- /45-Assignment-Q39/main.ts: -------------------------------------------------------------------------------- 1 | // 39. City Names: Write a function called city_country() that takes in the name 2 | // of a city and its country. The function should return a string formatted like this: 3 | // "Lahore, Pakistan" 4 | // Call your function with at least three city-country pairs, and print the value 5 | // that’s returned. 6 | 7 | function city_country(city: string, country: string) { 8 | return city.concat(", " + country); 9 | } 10 | console.log(city_country("Lahore", "Pakistan")); 11 | console.log(city_country("Tokyo", "Japan")); 12 | console.log(city_country("Paris", "France")); 13 | -------------------------------------------------------------------------------- /45-Assignment-Q07/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Q7. Number Eight: Write addition, subtraction, multiplication, and division operations 3 | // that each result in the number 8. Be sure to enclose your operations in print statements 4 | // to see the results. 5 | function add(num1, num2) { 6 | console.log(num1 + num2); 7 | } 8 | add(5, 3); 9 | function sub(num1, num2) { 10 | console.log(num1 - num2); 11 | } 12 | sub(10, 2); 13 | function mul(num1, num2) { 14 | console.log(num1 * num2); 15 | } 16 | mul(4, 2); 17 | function div(num1, num2) { 18 | console.log(num1 / num2); 19 | } 20 | div(64, 8); 21 | -------------------------------------------------------------------------------- /45-Assignment-Q12/main.ts: -------------------------------------------------------------------------------- 1 | // 12. Greetings: Start with the array you used in Exercise 11, but instead of just printing each person’s name, 2 | // print a message to them. The text of each message 3 | // should be the same, but each message should be personalized with the person’s name. 4 | 5 | let friends: string[] = ["Ubaid","Hamza","Subhan","Huzaifa","Abdullah"]; 6 | let message: string = "How Are You?"; 7 | console.log(`${friends[0]} ${message}`); 8 | console.log(`${friends[1]} ${message}`); 9 | console.log(`${friends[2]} ${message}`); 10 | console.log(`${friends[3]} ${message}`); 11 | console.log(`${friends[4]} ${message}`); 12 | -------------------------------------------------------------------------------- /Question-47/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 47: Advanced Array Destructuring: Given an array of objects representing different laptops, 3 | // each with properties make, model, and year, use array destructuring to assign the 4 | // first and second laptops to variables.Then, log these variables. 5 | const laptops = [ 6 | { make: "Dell", model: "XPS 13", year: 2020 }, 7 | { make: "Apple", model: "MacBook Pro", year: 2021 }, 8 | { make: "Lenovo", model: "ThinkPad X1", year: 2019 } 9 | ]; 10 | const [firstLaptop, secondLaptop] = laptops.slice(0, 2); 11 | console.log(firstLaptop); 12 | console.log(secondLaptop); 13 | -------------------------------------------------------------------------------- /Question-69/index.ts: -------------------------------------------------------------------------------- 1 | // Question 69: Dividing and Finding the Remainder: 2 | // Write a function that divides two numbers and returns both the quotient 3 | // and the remainder. Use an object to return both values. 4 | 5 | // This function divides two numbers and finds the quotient and remainder 6 | function divideAndRemainder(dividend: number, divisor: number): { quotient: number; remainder: number } { 7 | let quotient = Math.floor(dividend / divisor); 8 | let remainder = dividend % divisor; 9 | return { quotient, remainder }; 10 | } 11 | 12 | console.log(divideAndRemainder(10, 3)); // Shows { quotient: 3, remainder: 1 } -------------------------------------------------------------------------------- /Question-74/main.ts: -------------------------------------------------------------------------------- 1 | // Question 74: Swapping Variables: 2 | // Demonstrate how to swap the values of two variables. S 3 | // tart with variables a = 5 and b = 10, then swap their values so that a 4 | // becomes 10 and b becomes 5. 5 | function swapValues() { 6 | let a = 5, b = 10; // Initially, a is 5 and b is 10 7 | console.log("Before swap: a =", a, "b =", b); 8 | let temp = a; // Temporarily stores the value of a 9 | a = b; // Sets a to b's value 10 | b = temp; // Sets b to a's original value stored in temp 11 | console.log("After swap: a =", a, "b =", b); // Logs the swapped values 12 | } 13 | swapValues(); -------------------------------------------------------------------------------- /45-Assignment-Q38/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 38. Cities: Write a function called describe_city() that accepts the name of 3 | // a city and its country. The function should print a simple sentence, such as 4 | // Karachi is in Pakistan. Give the parameter for the country a default value. 5 | // Call your function for three different cities, at least one of which is not in the 6 | // default country. 7 | function describe_city(nameOfCity, nameOfCountry = "Pakistan") { 8 | console.log(`${nameOfCity} is in ${nameOfCountry}`); 9 | } 10 | describe_city("Karachi"); 11 | describe_city("Islamabad"); 12 | describe_city("Moscow", "Russia"); 13 | -------------------------------------------------------------------------------- /Question-59/index.ts: -------------------------------------------------------------------------------- 1 | // *Question 59:* Add a Special Number: Make a program that creates custom adders. 2 | // These adders can add a specific number to any other number you give them later. 3 | 4 | type CustomAdder = (n: number) => number; 5 | 6 | function addSpecialNumber(specialNumber: number): CustomAdder { 7 | if (typeof specialNumber !== 'number') { 8 | throw new Error('Expected a number for the special number'); 9 | } 10 | 11 | return (n: number): number => { 12 | return n + specialNumber; 13 | } 14 | } 15 | const adderThatAdds5 = addSpecialNumber(5); 16 | console.log(adderThatAdds5(3)); // Output: 8 -------------------------------------------------------------------------------- /45-Assignment-Q38/main.ts: -------------------------------------------------------------------------------- 1 | // 38. Cities: Write a function called describe_city() that accepts the name of 2 | // a city and its country. The function should print a simple sentence, such as 3 | // Karachi is in Pakistan. Give the parameter for the country a default value. 4 | // Call your function for three different cities, at least one of which is not in the 5 | // default country. 6 | 7 | function describe_city(nameOfCity: string, nameOfCountry: string = "Pakistan"): void { 8 | console.log(`${nameOfCity} is in ${nameOfCountry}`); 9 | } 10 | describe_city("Karachi"); 11 | describe_city("Islamabad"); 12 | describe_city("Moscow","Russia"); 13 | -------------------------------------------------------------------------------- /Question-53/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 53:* Pulling Apart a Nested Object: 2 | // Imagine you have a list inside another list that shows 3 | // what a computer programmer knows, like coding languages, tools, 4 | // and software frameworks. Find a way to get three specific skills 5 | // from this list and show them. 6 | 7 | let developerSkills = { 8 | languages: ["Javascript", "Typescript", "Python"], 9 | frameworks: ["React", "Angular", "Vue"], 10 | tools: ["Git", "Webpack", "Docker"] 11 | }; 12 | let { languages, frameworks, tools } = developerSkills; 13 | console.log(`Language: ${languages[0]}, Framework: ${frameworks[0]}, Tool: ${tools[0]}`); -------------------------------------------------------------------------------- /Question-62/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 62:* Making a Student Template: Create a blueprint for student 3 | // information, including their name, age, and the classes they're taking, 4 | // and then fill in this blueprint with an example student. 5 | const student = { 6 | name: 'Umar Farooq', 7 | age: 18, 8 | classes: [ 9 | { 10 | name: 'English', 11 | grade: 12 12 | }, 13 | { 14 | name: 'Math', 15 | grade: 11 16 | }, 17 | { 18 | name: 'Science', 19 | grade: 12 20 | } 21 | ] 22 | }; 23 | console.log(student); 24 | -------------------------------------------------------------------------------- /Question-74/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 74: Swapping Variables: 3 | // Demonstrate how to swap the values of two variables. S 4 | // tart with variables a = 5 and b = 10, then swap their values so that a 5 | // becomes 10 and b becomes 5. 6 | function swapValues() { 7 | let a = 5, b = 10; // Initially, a is 5 and b is 10 8 | console.log("Before swap: a =", a, "b =", b); 9 | let temp = a; // Temporarily stores the value of a 10 | a = b; // Sets a to b's value 11 | b = temp; // Sets b to a's original value stored in temp 12 | console.log("After swap: a =", a, "b =", b); // Logs the swapped values 13 | } 14 | swapValues(); 15 | -------------------------------------------------------------------------------- /Question-50/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 50:* Multiline Template Literals: 2 | // Use template literals to create a multiline string that describes your 3 | // ideal day. Include at least three different activities. 4 | 5 | const idealDay = ` 6 | My ideal day would start with a peaceful morning yoga session, 7 | followed by a delicious breakfast with a cup of freshly brewed coffee. 8 | In the afternoon, I would love to go for a hike in the beautiful mountains, 9 | taking in the breathtaking views and enjoying the sound of nature. 10 | The day would end with a relaxing evening reading a good book and watching the sunset. 11 | `; 12 | 13 | console.log(idealDay); -------------------------------------------------------------------------------- /Question-61/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 61:* Making Enums for Vehicles: 3 | // Let's create categories for vehicles like cars, trucks, and motorcycles using enums, 4 | // and show one example. 5 | var Vehicle; 6 | (function (Vehicle) { 7 | Vehicle["Car"] = "CAR"; 8 | Vehicle["Truck"] = "TRUCK"; 9 | Vehicle["Motorcycle"] = "MOTORCYCLE"; 10 | })(Vehicle || (Vehicle = {})); 11 | function isCar(vehicle) { 12 | return vehicle === Vehicle.Car; 13 | } 14 | // Usage 15 | let vehicleType = Vehicle.Car; 16 | if (isCar(vehicleType)) { 17 | console.log('This is a car'); 18 | } 19 | else { 20 | console.log('This is not a car'); 21 | } 22 | -------------------------------------------------------------------------------- /45-Assignment-Q37/main.ts: -------------------------------------------------------------------------------- 1 | // 37. Large Shirts: Modify the make_shirt() function so that shirts are large 2 | // by default with a message that reads I love TypeScript. Make a large shirt and a 3 | // medium shirt with the default message, and a shirt of any size with a different 4 | // message. 5 | 6 | function make_shirt(size: string = "Large", message: string = "I love TypeScript"): void { 7 | console.log(`You ordered a ${size} shirt with the message: "${message}"`); 8 | } 9 | make_shirt(); // Large shirt with default message 10 | make_shirt("Medium"); // Medium shirt with default message 11 | make_shirt("Small", "Hello, World!"); // Custom size and message shirt -------------------------------------------------------------------------------- /Question-53/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 53:* Pulling Apart a Nested Object: 3 | // Imagine you have a list inside another list that shows 4 | // what a computer programmer knows, like coding languages, tools, 5 | // and software frameworks. Find a way to get three specific skills 6 | // from this list and show them. 7 | let developerSkills = { 8 | languages: ["Javascript", "Typescript", "Python"], 9 | frameworks: ["React", "Angular", "Vue"], 10 | tools: ["Git", "Webpack", "Docker"] 11 | }; 12 | let { languages, frameworks, tools } = developerSkills; 13 | console.log(`Language: ${languages[0]}, Framework: ${frameworks[0]}, Tool: ${tools[0]}`); 14 | -------------------------------------------------------------------------------- /45-Assignment-Q07/main.ts: -------------------------------------------------------------------------------- 1 | // Q7. Number Eight: Write addition, subtraction, multiplication, and division operations 2 | // that each result in the number 8. Be sure to enclose your operations in print statements 3 | // to see the results. 4 | 5 | function add(num1: number, num2: number) { 6 | console.log(num1 + num2); 7 | } 8 | add(5, 3); 9 | 10 | function sub(num1: number, num2: number) { 11 | console.log(num1 - num2); 12 | } 13 | sub(10, 2); 14 | 15 | function mul(num1: number, num2: number) { 16 | console.log(num1 * num2); 17 | } 18 | mul(4, 2); 19 | 20 | function div(num1: number, num2: number) { 21 | console.log(num1 / num2); 22 | } 23 | div(64, 8); -------------------------------------------------------------------------------- /Question-50/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 50:* Multiline Template Literals: 3 | // Use template literals to create a multiline string that describes your 4 | // ideal day. Include at least three different activities. 5 | const idealDay = ` 6 | My ideal day would start with a peaceful morning yoga session, 7 | followed by a delicious breakfast with a cup of freshly brewed coffee. 8 | In the afternoon, I would love to go for a hike in the beautiful mountains, 9 | taking in the breathtaking views and enjoying the sound of nature. 10 | The day would end with a relaxing evening reading a good book and watching the sunset. 11 | `; 12 | console.log(idealDay); 13 | -------------------------------------------------------------------------------- /45-Assignment-Q12/main.js: -------------------------------------------------------------------------------- 1 | // 12. Greetings: Start with the array you used in Exercise 11, but instead of just printing each person’s name, 2 | // print a message to them. The text of each message 3 | // should be the same, but each message should be personalized with the person’s name. 4 | var friends = ["Ubaid", "Hamza", "Subhan", "Huzaifa", "Abdullah"]; 5 | var message = "How Are You?"; 6 | console.log("".concat(friends[0], " ").concat(message)); 7 | console.log("".concat(friends[1], " ").concat(message)); 8 | console.log("".concat(friends[2], " ").concat(message)); 9 | console.log("".concat(friends[3], " ").concat(message)); 10 | console.log("".concat(friends[4], " ").concat(message)); 11 | -------------------------------------------------------------------------------- /Question-54/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 54:* Making Flexible Object Keys: 2 | // Learn how to set up a list where you can change the name of each section 3 | // based on what you need at that moment, like adjusting labels based on user 4 | // choices. 5 | // A way to make a flexible list 6 | interface user { 7 | [key: string]: string 8 | } 9 | function createObjectWithDynamicKey(key: string, value: string): user { 10 | let dynamicObject: user = {}; 11 | // Setting up a section in the list with a changeable name 12 | dynamicObject[key] = value; 13 | return dynamicObject; 14 | } 15 | let userPreference = createObjectWithDynamicKey("theme", "dark"); 16 | console.log(userPreference); -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/content-type.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | interface MIMEType { 4 | type: string 5 | subtype: string 6 | parameters: Map 7 | essence: string 8 | } 9 | 10 | /** 11 | * Parse a string to a {@link MIMEType} object. Returns `failure` if the string 12 | * couldn't be parsed. 13 | * @see https://mimesniff.spec.whatwg.org/#parse-a-mime-type 14 | */ 15 | export function parseMIMEType (input: string): 'failure' | MIMEType 16 | 17 | /** 18 | * Convert a MIMEType object to a string. 19 | * @see https://mimesniff.spec.whatwg.org/#serialize-a-mime-type 20 | */ 21 | export function serializeAMimeType (mimeType: MIMEType): string 22 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/balanced-pool.d.ts: -------------------------------------------------------------------------------- 1 | import Pool from './pool' 2 | import Dispatcher from './dispatcher' 3 | import { URL } from 'url' 4 | 5 | export default BalancedPool 6 | 7 | declare class BalancedPool extends Dispatcher { 8 | constructor(url: string | string[] | URL | URL[], options?: Pool.Options); 9 | 10 | addUpstream(upstream: string | URL): BalancedPool; 11 | removeUpstream(upstream: string | URL): BalancedPool; 12 | upstreams: Array; 13 | 14 | /** `true` after `pool.close()` has been called. */ 15 | closed: boolean; 16 | /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */ 17 | destroyed: boolean; 18 | } 19 | -------------------------------------------------------------------------------- /45-Assignment-Q42/main.js: -------------------------------------------------------------------------------- 1 | // 42. Great Magicians: Start with a copy of your program from Exercise 39. 2 | // Write a function called make_great() that modifies the array of magicians by adding 3 | // the phrase the Great to each magician’s name. Call show_magicians() to 4 | // see that the list has actually been modified. 5 | function make_great(magicians) { 6 | return magicians.map(function (magician) { return "TheGreat ".concat(magician); }); 7 | } 8 | // Define the array of magicians 9 | var magicians = ["Harry Houdini", "David Copperfield", "Penn Jillette"]; 10 | // Call makeGreat() to modify the array 11 | var greatMagicians = make_great(magicians); 12 | // Print the modified list of magicians 13 | console.log(greatMagicians); 14 | -------------------------------------------------------------------------------- /Question-47/index.ts: -------------------------------------------------------------------------------- 1 | // Question 47: Advanced Array Destructuring: Given an array of objects representing different laptops, 2 | // each with properties make, model, and year, use array destructuring to assign the 3 | // first and second laptops to variables.Then, log these variables. 4 | 5 | interface Laptop { 6 | make: string; 7 | model: string; 8 | year: number; 9 | } 10 | 11 | const laptops: Laptop[] = [ 12 | { make: "Dell", model: "XPS 13", year: 2020 }, 13 | { make: "Apple", model: "MacBook Pro", year: 2021 }, 14 | { make: "Lenovo", model: "ThinkPad X1", year: 2019 } 15 | ]; 16 | 17 | const [firstLaptop, secondLaptop] = laptops.slice(0, 2); 18 | 19 | console.log(firstLaptop); 20 | console.log(secondLaptop); -------------------------------------------------------------------------------- /45-Assignment-Q37/main.js: -------------------------------------------------------------------------------- 1 | // 37. Large Shirts: Modify the make_shirt() function so that shirts are large 2 | // by default with a message that reads I love TypeScript. Make a large shirt and a 3 | // medium shirt with the default message, and a shirt of any size with a different 4 | // message. 5 | function make_shirt(size, message) { 6 | if (size === void 0) { size = "Large"; } 7 | if (message === void 0) { message = "I love TypeScript"; } 8 | console.log("You ordered a ".concat(size, " shirt with the message: \"").concat(message, "\"")); 9 | } 10 | make_shirt(); // Large shirt with default message 11 | make_shirt("Medium"); // Medium shirt with default message 12 | make_shirt("Small", "Hello, World!"); // Custom size and message shirt 13 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/constants.d.ts: -------------------------------------------------------------------------------- 1 | /** @deprecated since v6.3.0 - use constants property exposed by the relevant module instead. */ 2 | declare module "constants" { 3 | import { constants as osConstants, SignalConstants } from "node:os"; 4 | import { constants as cryptoConstants } from "node:crypto"; 5 | import { constants as fsConstants } from "node:fs"; 6 | 7 | const exp: 8 | & typeof osConstants.errno 9 | & typeof osConstants.priority 10 | & SignalConstants 11 | & typeof cryptoConstants 12 | & typeof fsConstants; 13 | export = exp; 14 | } 15 | 16 | declare module "node:constants" { 17 | import constants = require("constants"); 18 | export = constants; 19 | } 20 | -------------------------------------------------------------------------------- /Question-63/index.ts: -------------------------------------------------------------------------------- 1 | // *Question 63:* Shape Shifter: 2 | // Write a program that can describe either a circle or a rectangle using a 3 | // special type alias, including properties unique to each shape. 4 | type Shape = { 5 | kind: "circle" | "rectangle"; 6 | radius?: number; 7 | width?: number; 8 | height?: number; 9 | }; 10 | // Describing a circle using our Shape type 11 | let circle: Shape = { 12 | kind: "circle", 13 | radius: 5 14 | }; 15 | // Describing a rectangle using our Shape type 16 | let rectangle: Shape = { 17 | kind: "rectangle", 18 | width: 10, 19 | height: 20 20 | }; 21 | // Showing what we described 22 | console.log(circle); // Here's the circle 23 | console.log(rectangle); // And here's the rectangle -------------------------------------------------------------------------------- /45-Assignment-Q10/main.js: -------------------------------------------------------------------------------- 1 | // 10. Adding Comments: Choose two of the programs you’ve written, and add at least one comment to each. 2 | // If you don’t have anything specific to write 3 | // because your programs are too simple at this point, 4 | // just add your name and the current date at the top of each program file. Then write one sentence 5 | // describing what the program does. 6 | // My Name is Umar Farooq 7 | // My Number is 0317 2472531 8 | var num1 = 1; 9 | var num2 = 21; 10 | var sum = num1 + num2; 11 | console.log("The Sum of num1 and num2 is ".concat(sum)); 12 | // in this program we declare and initialize two variables with some numbers and in third variable 13 | // we added them and then we display the sum of these vars as a result in console 14 | -------------------------------------------------------------------------------- /45-Assignment-Q42/main.ts: -------------------------------------------------------------------------------- 1 | // 42. Great Magicians: Start with a copy of your program from Exercise 39. 2 | // Write a function called make_great() that modifies the array of magicians by adding 3 | // the phrase the Great to each magician’s name. Call show_magicians() to 4 | // see that the list has actually been modified. 5 | 6 | function make_great(magicians: string[]): string[] { 7 | return magicians.map(magician => `TheGreat ${magician}`); 8 | } 9 | 10 | // Define the array of magicians 11 | const magicians: string[] = ["Harry Houdini", "David Copperfield", "Penn Jillette"]; 12 | 13 | // Call makeGreat() to modify the array 14 | const greatMagicians: string[] = make_great(magicians); 15 | 16 | // Print the modified list of magicians 17 | console.log(greatMagicians); -------------------------------------------------------------------------------- /45-Assignment-Q44/main.ts: -------------------------------------------------------------------------------- 1 | // 44. Sandwiches: Write a function that accepts a array of items a person wants on a sandwich. 2 | // The function should have one parameter that collects as many items as the function call provides, 3 | // and it should print a summary of the sandwich that is being ordered. Call the function three times, 4 | // using a different number of arguments each time. 5 | 6 | function orderSandwich(...items: string[]) { 7 | console.log("You ordered a sandwich with:"); 8 | for (let item of items) { 9 | console.log("- " + item); 10 | } 11 | } 12 | 13 | // Calling the function with different number of arguments 14 | orderSandwich("Ham", "Cheese", "Lettuce"); 15 | orderSandwich("Turkey", "Tomato"); 16 | orderSandwich("Peanut Butter", "Jelly", "Banana"); -------------------------------------------------------------------------------- /45-Assignment-Q10/main.ts: -------------------------------------------------------------------------------- 1 | // 10. Adding Comments: Choose two of the programs you’ve written, and add at least one comment to each. 2 | // If you don’t have anything specific to write 3 | // because your programs are too simple at this point, 4 | // just add your name and the current date at the top of each program file. Then write one sentence 5 | // describing what the program does. 6 | 7 | // My Name is Umar Farooq 8 | // My Number is 0317 2472531 9 | 10 | let num1: number = 1; 11 | let num2: number = 21; 12 | let sum: number = num1 + num2; 13 | console.log(`The Sum of num1 and num2 is ${sum}`); 14 | 15 | // in this program we declare and initialize two variables with some numbers and in third variable 16 | // we added them and then we display the sum of these vars as a result in console -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/pool-stats.d.ts: -------------------------------------------------------------------------------- 1 | import Pool from "./pool" 2 | 3 | export default PoolStats 4 | 5 | declare class PoolStats { 6 | constructor(pool: Pool); 7 | /** Number of open socket connections in this pool. */ 8 | connected: number; 9 | /** Number of open socket connections in this pool that do not have an active request. */ 10 | free: number; 11 | /** Number of pending requests across all clients in this pool. */ 12 | pending: number; 13 | /** Number of queued requests across all clients in this pool. */ 14 | queued: number; 15 | /** Number of currently active requests across all clients in this pool. */ 16 | running: number; 17 | /** Number of active, pending, or queued requests across all clients in this pool. */ 18 | size: number; 19 | } 20 | -------------------------------------------------------------------------------- /45-Assignment-Q25/main.js: -------------------------------------------------------------------------------- 1 | // 25. Alien Colors #1: Imagine an alien was just shot down in a game. Create a 2 | // variable called alien_color and assign it a value of 'green', 'yellow', or 'red'. 3 | // • Write an if statement to test whether the alien’s color is green. If it is, print 4 | // a message that the player just earned 5 points. 5 | // • Write one version of this program that passes the if test and another that 6 | // fails. (The version that fails will have no output.) 7 | var alien_color = "green"; 8 | if (alien_color == "green") { 9 | console.log("The Player Just Earned 5 Points"); 10 | } 11 | else { 12 | console.log("You Guessed Incorrect"); 13 | } 14 | var alien_color2 = "yellow"; 15 | if (alien_color2 === "red") { 16 | console.log("The Player Just Earned 5 Points"); 17 | } 18 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/cookies.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import type { Headers } from './fetch' 4 | 5 | export interface Cookie { 6 | name: string 7 | value: string 8 | expires?: Date | number 9 | maxAge?: number 10 | domain?: string 11 | path?: string 12 | secure?: boolean 13 | httpOnly?: boolean 14 | sameSite?: 'Strict' | 'Lax' | 'None' 15 | unparsed?: string[] 16 | } 17 | 18 | export function deleteCookie ( 19 | headers: Headers, 20 | name: string, 21 | attributes?: { name?: string, domain?: string } 22 | ): void 23 | 24 | export function getCookies (headers: Headers): Record 25 | 26 | export function getSetCookies (headers: Headers): Cookie[] 27 | 28 | export function setCookie (headers: Headers, cookie: Cookie): void 29 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/stream/consumers.d.ts: -------------------------------------------------------------------------------- 1 | declare module "stream/consumers" { 2 | import { Blob as NodeBlob } from "node:buffer"; 3 | import { Readable } from "node:stream"; 4 | function buffer(stream: NodeJS.ReadableStream | Readable | AsyncIterable): Promise; 5 | function text(stream: NodeJS.ReadableStream | Readable | AsyncIterable): Promise; 6 | function arrayBuffer(stream: NodeJS.ReadableStream | Readable | AsyncIterable): Promise; 7 | function blob(stream: NodeJS.ReadableStream | Readable | AsyncIterable): Promise; 8 | function json(stream: NodeJS.ReadableStream | Readable | AsyncIterable): Promise; 9 | } 10 | declare module "node:stream/consumers" { 11 | export * from "stream/consumers"; 12 | } 13 | -------------------------------------------------------------------------------- /Question-62/main.ts: -------------------------------------------------------------------------------- 1 | // *Question 62:* Making a Student Template: Create a blueprint for student 2 | // information, including their name, age, and the classes they're taking, 3 | // and then fill in this blueprint with an example student. 4 | 5 | type Class = { 6 | name: string; 7 | grade: number; 8 | }; 9 | interface Student { 10 | name: string; 11 | age: number; 12 | classes: Class[]; 13 | } 14 | const student: Student = { 15 | name: 'Umar Farooq', 16 | age: 18, 17 | classes: [ 18 | { 19 | name: 'English', 20 | grade: 12 21 | }, 22 | { 23 | name: 'Math', 24 | grade: 11 25 | }, 26 | { 27 | name: 'Science', 28 | grade: 12 29 | } 30 | ] 31 | }; 32 | console.log(student); -------------------------------------------------------------------------------- /45-Assignment-Q26/main.js: -------------------------------------------------------------------------------- 1 | // 26. Alien Colors #2: Choose a color for an alien as you did in Exercise 25, and 2 | // write an if-else chain. 3 | // • If the alien’s color is green, print a statement that the player just earned 5 points for 4 | // shooting the alien. 5 | // • If the alien’s color isn’t green, print a statement that the player just earned 10 points. 6 | // • Write one version of this program that runs the if block and another that runs the else block. 7 | var alienColor = "green"; 8 | if (alienColor === "green") { 9 | console.log("player just earned 5 points for shooting the alien!"); 10 | } 11 | alienColor = "red"; 12 | if (alienColor === "green") { 13 | console.log("player just earned 5 points for shooting the alien!"); 14 | } 15 | else { 16 | console.log("the player just earned 10 points."); 17 | } 18 | -------------------------------------------------------------------------------- /45-Assignment-Q25/main.ts: -------------------------------------------------------------------------------- 1 | // 25. Alien Colors #1: Imagine an alien was just shot down in a game. Create a 2 | // variable called alien_color and assign it a value of 'green', 'yellow', or 'red'. 3 | 4 | // • Write an if statement to test whether the alien’s color is green. If it is, print 5 | // a message that the player just earned 5 points. 6 | 7 | // • Write one version of this program that passes the if test and another that 8 | // fails. (The version that fails will have no output.) 9 | 10 | const alien_color: string = "green"; 11 | if (alien_color == "green"){ 12 | console.log("The Player Just Earned 5 Points"); 13 | } else { 14 | console.log("You Guessed Incorrect"); 15 | } 16 | 17 | const alien_color2: string = "yellow"; 18 | 19 | if(alien_color2 === "red"){ 20 | console.log("The Player Just Earned 5 Points"); 21 | } -------------------------------------------------------------------------------- /45-Assignment-Q30/main.ts: -------------------------------------------------------------------------------- 1 | // 30. Hello Admin: Make a array of five or more usernames, including the name 'admin'. 2 | // Imagine you are writing code that will print a greeting to each user 3 | // after they log in to a website. Loop through the array, and print a greeting to each user: 4 | // • If the username is 'admin', print a special greeting, such as Hello admin, 5 | // would you like to see a status report? 6 | // • Otherwise, print a generic greeting, such as Hello Eric, thank you for logging in again. 7 | 8 | let userNames: string[] = ["eric", "john", "admin", "bob", "ever"]; 9 | userNames.forEach((val) => { 10 | if (val === "admin") { 11 | console.log("Hello admin, would you like to see a status report?"); 12 | } else { 13 | console.log(`Hello ${val} Thank you for logging in again.`); 14 | } 15 | }); -------------------------------------------------------------------------------- /45-Assignment-Q33/main.ts: -------------------------------------------------------------------------------- 1 | // 33. Ordinal Numbers: Ordinal numbers indicate their position in a array, 2 | // such as 1st or 2nd. Most ordinal numbers end in th, except 1, 2, and 3. 3 | // • Store the numbers 1 through 9 in a array. 4 | // • Loop through the array. 5 | // • Use an if-else chain inside the loop to print the proper ordinal ending for each number. 6 | // Your output should read "1st 2nd 3rd 4th 5th 6th 7 | // 7th 8th 9th", and each result should be on a separate line. 8 | 9 | let numbers: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 10 | numbers.forEach((val) => { 11 | let ordinal: string; 12 | if (val === 1) { 13 | ordinal = "1st"; 14 | } else if (val === 2) { 15 | ordinal = "2nd"; 16 | } else if (val === 3) { 17 | ordinal = "3rd"; 18 | } else { 19 | ordinal = `${val}th`; 20 | } 21 | console.log(ordinal); 22 | }) -------------------------------------------------------------------------------- /45-Assignment-Q30/main.js: -------------------------------------------------------------------------------- 1 | // 30. Hello Admin: Make a array of five or more usernames, including the name 'admin'. 2 | // Imagine you are writing code that will print a greeting to each user 3 | // after they log in to a website. Loop through the array, and print a greeting to each user: 4 | // • If the username is 'admin', print a special greeting, such as Hello admin, 5 | // would you like to see a status report? 6 | // • Otherwise, print a generic greeting, such as Hello Eric, thank you for logging in again. 7 | var userNames = ["eric", "john", "admin", "bob", "ever"]; 8 | userNames.forEach(function (val) { 9 | if (val === "admin") { 10 | console.log("Hello admin, would you like to see a status report?"); 11 | } 12 | else { 13 | console.log("Hello ".concat(val, " Thank you for logging in again.")); 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /45-Assignment-Q26/main.ts: -------------------------------------------------------------------------------- 1 | // 26. Alien Colors #2: Choose a color for an alien as you did in Exercise 25, and 2 | // write an if-else chain. 3 | 4 | // • If the alien’s color is green, print a statement that the player just earned 5 points for 5 | // shooting the alien. 6 | 7 | // • If the alien’s color isn’t green, print a statement that the player just earned 10 points. 8 | 9 | // • Write one version of this program that runs the if block and another that runs the else block. 10 | 11 | let alienColor: string = "green"; 12 | if (alienColor === "green") { 13 | console.log("player just earned 5 points for shooting the alien!"); 14 | } 15 | 16 | alienColor = "red" 17 | 18 | if (alienColor === "green") { 19 | console.log("player just earned 5 points for shooting the alien!"); 20 | } else { 21 | console.log("the player just earned 10 points."); 22 | } -------------------------------------------------------------------------------- /Question-75/main.ts: -------------------------------------------------------------------------------- 1 | // Question 75: Compound Assignment Operators: 2 | // Use compound assignment operators to simplify arithmetic operations. 3 | // Start with x = 4 and perform a series of operations 4 | // (addition, subtraction, multiplication, division) on x using compound operators. 5 | function useCompoundOperators() { 6 | let x = 4; // Starts with x equal to 4 7 | console.log("Initial x:", x); 8 | x += 2; // Adds 2 to x 9 | console.log("After addition:", x); // Shows x after addition 10 | x -= 1; // Subtracts 1 from x 11 | console.log("After subtraction:", x); // Shows x after subtraction 12 | x *= 3; // Multiplies x by 3 13 | console.log("After multiplication:", x); // Shows x after multiplication 14 | x /= 2; // Divides x by 2 15 | console.log("After division:", x); // Shows x after division 16 | } 17 | useCompoundOperators(); -------------------------------------------------------------------------------- /Question-60/node_modules/.package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "question-60", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "node_modules/@types/node": { 8 | "version": "20.12.2", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.2.tgz", 10 | "integrity": "sha512-zQ0NYO87hyN6Xrclcqp7f8ZbXNbRfoGWNcMvHTPQp9UUrwI0mI7XBz+cu7/W6/VClYo2g63B0cjull/srU7LgQ==", 11 | "dev": true, 12 | "dependencies": { 13 | "undici-types": "~5.26.4" 14 | } 15 | }, 16 | "node_modules/undici-types": { 17 | "version": "5.26.5", 18 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", 19 | "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", 20 | "dev": true 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Question-75/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 75: Compound Assignment Operators: 3 | // Use compound assignment operators to simplify arithmetic operations. 4 | // Start with x = 4 and perform a series of operations 5 | // (addition, subtraction, multiplication, division) on x using compound operators. 6 | function useCompoundOperators() { 7 | let x = 4; // Starts with x equal to 4 8 | console.log("Initial x:", x); 9 | x += 2; // Adds 2 to x 10 | console.log("After addition:", x); // Shows x after addition 11 | x -= 1; // Subtracts 1 from x 12 | console.log("After subtraction:", x); // Shows x after subtraction 13 | x *= 3; // Multiplies x by 3 14 | console.log("After multiplication:", x); // Shows x after multiplication 15 | x /= 2; // Divides x by 2 16 | console.log("After division:", x); // Shows x after division 17 | } 18 | useCompoundOperators(); 19 | -------------------------------------------------------------------------------- /45-Assignment-Q33/main.js: -------------------------------------------------------------------------------- 1 | // 33. Ordinal Numbers: Ordinal numbers indicate their position in a array, 2 | // such as 1st or 2nd. Most ordinal numbers end in th, except 1, 2, and 3. 3 | // • Store the numbers 1 through 9 in a array. 4 | // • Loop through the array. 5 | // • Use an if-else chain inside the loop to print the proper ordinal ending for each number. 6 | // Your output should read "1st 2nd 3rd 4th 5th 6th 7 | // 7th 8th 9th", and each result should be on a separate line. 8 | var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 9 | numbers.forEach(function (val) { 10 | var ordinal; 11 | if (val === 1) { 12 | ordinal = "1st"; 13 | } 14 | else if (val === 2) { 15 | ordinal = "2nd"; 16 | } 17 | else if (val === 3) { 18 | ordinal = "3rd"; 19 | } 20 | else { 21 | ordinal = "".concat(val, "th"); 22 | } 23 | console.log(ordinal); 24 | }); 25 | -------------------------------------------------------------------------------- /45-Assignment-Q34/main.ts: -------------------------------------------------------------------------------- 1 | // 34. Pizzas: Think of at least three kinds of your favorite pizza. Store these 2 | // pizza names in a array, and then use a for loop to print the name of each pizza. 3 | // • Modify your for loop to print a sentence using the name of the pizza 4 | // instead of printing just the name of the pizza. For each pizza you should 5 | // have one line of output containing a simple statement like I like pepperoni 6 | // pizza. 7 | // • Add a line at the end of your program, outside the for loop, that states 8 | // how much you like pizza. The output should consist of three or more lines 9 | // about the kinds of pizza you like and then an additional sentence, such as 10 | // I really love pizza! 11 | 12 | let pizzas: string[] = ["Pepperoni", "Margherita", "BBQ Chicken", "Fajita"]; 13 | pizzas.forEach((str) => { 14 | console.log(`I Like ${str} Pizza.`); 15 | }) 16 | console.log("I really love pizza!"); -------------------------------------------------------------------------------- /45-Assignment-Q34/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 34. Pizzas: Think of at least three kinds of your favorite pizza. Store these 3 | // pizza names in a array, and then use a for loop to print the name of each pizza. 4 | // • Modify your for loop to print a sentence using the name of the pizza 5 | // instead of printing just the name of the pizza. For each pizza you should 6 | // have one line of output containing a simple statement like I like pepperoni 7 | // pizza. 8 | // • Add a line at the end of your program, outside the for loop, that states 9 | // how much you like pizza. The output should consist of three or more lines 10 | // about the kinds of pizza you like and then an additional sentence, such as 11 | // I really love pizza! 12 | let pizzas = ["Pepperoni", "Margherita", "BBQ Chicken", "Fajita"]; 13 | pizzas.forEach((str) => { 14 | console.log(`I Like ${str} Pizza.`); 15 | }); 16 | console.log("I really love pizza!"); 17 | -------------------------------------------------------------------------------- /Question-72/index.ts: -------------------------------------------------------------------------------- 1 | // Question 72: Block Scope with let and const: 2 | // Demonstrate block scope by creating a code block with {} that uses both let and const. 3 | // Show how variables declared inside the block are not accessible outside of it. 4 | 5 | // Demonstrating block scope 6 | { 7 | let blockLet = "visible inside the block"; 8 | const blockConst = "also only inside the block"; 9 | console.log(blockLet); // Works fine here 10 | console.log(blockConst); // Also works fine here 11 | } 12 | try { 13 | console.log(blockLet); // This will fail 14 | } catch (error) { 15 | console.log("`blockLet` is not accessible outside the block."); 16 | } 17 | try { 18 | console.log(blockConst); // This will also fail 19 | } catch (error) { 20 | console.log("`blockConst` is not accessible outside the block."); 21 | } 22 | // This shows that `let` and `const` keep variables safe inside the block where they defined -------------------------------------------------------------------------------- /45-Assignment-Q45/main.ts: -------------------------------------------------------------------------------- 1 | // 45. Cars: Write a function that stores information about a car in a Object. 2 | // The function should always receive a manufacturer and a model name. 3 | // It should then accept an arbitrary number of keyword arguments. 4 | // Call the function with the required information and two other name-value pairs, 5 | // such as a color or an optional feature. Print the Object that’s 6 | // returned to make sure all the information was stored correctly. 7 | 8 | interface Car { 9 | manufacturer: string; 10 | model: string; 11 | [key: string]: any; 12 | } 13 | 14 | function createCar(manufacturer: string, model: string, ...options: [string, any][]): Car { 15 | const car: Car = { manufacturer, model }; 16 | options.forEach(([key, value]) => { 17 | car[key] = value; 18 | }); 19 | return car; 20 | } 21 | 22 | const myCar = createCar("Toyota", "Camry", ["color", "red"], ["year", 2024]); 23 | console.log(myCar); -------------------------------------------------------------------------------- /Question-72/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Question 72: Block Scope with let and const: 3 | // Demonstrate block scope by creating a code block with {} that uses both let and const. 4 | // Show how variables declared inside the block are not accessible outside of it. 5 | // Demonstrating block scope 6 | { 7 | let blockLet = "visible inside the block"; 8 | const blockConst = "also only inside the block"; 9 | console.log(blockLet); // Works fine here 10 | console.log(blockConst); // Also works fine here 11 | } 12 | try { 13 | console.log(blockLet); // This will fail 14 | } 15 | catch (error) { 16 | console.log("`blockLet` is not accessible outside the block."); 17 | } 18 | try { 19 | console.log(blockConst); // This will also fail 20 | } 21 | catch (error) { 22 | console.log("`blockConst` is not accessible outside the block."); 23 | } 24 | // This shows that `let` and `const` keep variables safe inside the block where they defined 25 | -------------------------------------------------------------------------------- /45-Assignment-Q44/main.js: -------------------------------------------------------------------------------- 1 | // 44. Sandwiches: Write a function that accepts a array of items a person wants on a sandwich. 2 | // The function should have one parameter that collects as many items as the function call provides, 3 | // and it should print a summary of the sandwich that is being ordered. Call the function three times, 4 | // using a different number of arguments each time. 5 | function orderSandwich() { 6 | var items = []; 7 | for (var _i = 0; _i < arguments.length; _i++) { 8 | items[_i] = arguments[_i]; 9 | } 10 | console.log("You ordered a sandwich with:"); 11 | for (var _a = 0, items_1 = items; _a < items_1.length; _a++) { 12 | var item = items_1[_a]; 13 | console.log("- " + item); 14 | } 15 | } 16 | // Calling the function with different number of arguments 17 | orderSandwich("Ham", "Cheese", "Lettuce"); 18 | orderSandwich("Turkey", "Tomato"); 19 | orderSandwich("Peanut Butter", "Jelly", "Banana"); 20 | -------------------------------------------------------------------------------- /45-Assignment-Q45/main.js: -------------------------------------------------------------------------------- 1 | // 45. Cars: Write a function that stores information about a car in a Object. 2 | // The function should always receive a manufacturer and a model name. 3 | // It should then accept an arbitrary number of keyword arguments. 4 | // Call the function with the required information and two other name-value pairs, 5 | // such as a color or an optional feature. Print the Object that’s 6 | // returned to make sure all the information was stored correctly. 7 | function createCar(manufacturer, model) { 8 | var options = []; 9 | for (var _i = 2; _i < arguments.length; _i++) { 10 | options[_i - 2] = arguments[_i]; 11 | } 12 | var car = { manufacturer: manufacturer, model: model }; 13 | options.forEach(function (_a) { 14 | var key = _a[0], value = _a[1]; 15 | car[key] = value; 16 | }); 17 | return car; 18 | } 19 | var myCar = createCar("Toyota", "Camry", ["color", "red"], ["year", 2024]); 20 | console.log(myCar); 21 | -------------------------------------------------------------------------------- /45-Assignment-Q35/main.ts: -------------------------------------------------------------------------------- 1 | // 35. Animals: Think of at least three different animals that have a common characteristic. 2 | // Store the names of these animals in a list, and then use a for loop to 3 | // print out the name of each animal. 4 | // • Modify your program to print a statement about each animal, such as 5 | // A dog would make a great pet. 6 | // • Add a line at the end of your program stating what these animals have in 7 | // common. You could print a sentence such as Any of these animals would 8 | // make a great pet! 9 | 10 | let animals: string[] = ["dog", "cat", "rabbit"]; 11 | animals.forEach((str) => { 12 | console.log(str); 13 | if (str === "dog") { 14 | console.log("A dog would make a great pet."); 15 | } else if (str === "cat") { 16 | console.log("A cat would be a wonderful companion."); 17 | } else if (str === "rabbit") { 18 | console.log("A rabbit can bring joy to your home."); 19 | } 20 | }) 21 | console.log("Any of these animals would make a great pet!"); 22 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/proxy-agent.d.ts: -------------------------------------------------------------------------------- 1 | import Agent from './agent' 2 | import buildConnector from './connector'; 3 | import Client from './client' 4 | import Dispatcher from './dispatcher' 5 | import { IncomingHttpHeaders } from './header' 6 | import Pool from './pool' 7 | 8 | export default ProxyAgent 9 | 10 | declare class ProxyAgent extends Dispatcher { 11 | constructor(options: ProxyAgent.Options | string) 12 | 13 | dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean; 14 | close(): Promise; 15 | } 16 | 17 | declare namespace ProxyAgent { 18 | export interface Options extends Agent.Options { 19 | uri: string; 20 | /** 21 | * @deprecated use opts.token 22 | */ 23 | auth?: string; 24 | token?: string; 25 | headers?: IncomingHttpHeaders; 26 | requestTls?: buildConnector.BuildOptions; 27 | proxyTls?: buildConnector.BuildOptions; 28 | clientFactory?(origin: URL, opts: object): Dispatcher; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /45-Assignment-Q29/main.js: -------------------------------------------------------------------------------- 1 | // 29. Favorite Fruit: Make a array of your favorite fruits, and then write a series of independent 2 | // if statements that check for certain fruits in your array. 3 | // • Make a array of your three favorite fruits and call it favorite_fruits. 4 | // • Write five if statements. Each should check whether a certain kind of fruit is in your array. 5 | // If the fruit is in your array, the if block should print a statement, such as You really like bananas! 6 | var favorite_fruits = ["apple", "mango", "banana"]; 7 | if (favorite_fruits.includes("apple")) { 8 | console.log("you really like apple"); 9 | } 10 | if (favorite_fruits.includes("mango")) { 11 | console.log("you really like mango"); 12 | } 13 | if (favorite_fruits.includes("banana")) { 14 | console.log("you really like banana"); 15 | } 16 | if (favorite_fruits.includes("orange")) { 17 | console.log("you really like orange"); 18 | } 19 | if (favorite_fruits.includes("grapes")) { 20 | console.log("you really like grapes"); 21 | } 22 | -------------------------------------------------------------------------------- /45-Assignment-Q29/main.ts: -------------------------------------------------------------------------------- 1 | // 29. Favorite Fruit: Make a array of your favorite fruits, and then write a series of independent 2 | // if statements that check for certain fruits in your array. 3 | // • Make a array of your three favorite fruits and call it favorite_fruits. 4 | // • Write five if statements. Each should check whether a certain kind of fruit is in your array. 5 | // If the fruit is in your array, the if block should print a statement, such as You really like bananas! 6 | 7 | let favorite_fruits: string[] = ["apple", "mango", "banana"]; 8 | if (favorite_fruits.includes("apple")) { 9 | console.log("you really like apple"); 10 | } 11 | if (favorite_fruits.includes("mango")) { 12 | console.log("you really like mango"); 13 | } 14 | if (favorite_fruits.includes("banana")) { 15 | console.log("you really like banana"); 16 | } 17 | if (favorite_fruits.includes("orange")) { 18 | console.log("you really like orange"); 19 | } 20 | if (favorite_fruits.includes("grapes")) { 21 | console.log("you really like grapes"); 22 | } 23 | -------------------------------------------------------------------------------- /45-Assignment-Q35/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 35. Animals: Think of at least three different animals that have a common characteristic. 3 | // Store the names of these animals in a list, and then use a for loop to 4 | // print out the name of each animal. 5 | // • Modify your program to print a statement about each animal, such as 6 | // A dog would make a great pet. 7 | // • Add a line at the end of your program stating what these animals have in 8 | // common. You could print a sentence such as Any of these animals would 9 | // make a great pet! 10 | let animals = ["dog", "cat", "rabbit"]; 11 | animals.forEach((str) => { 12 | console.log(str); 13 | if (str === "dog") { 14 | console.log("A dog would make a great pet."); 15 | } 16 | else if (str === "cat") { 17 | console.log("A cat would be a wonderful companion."); 18 | } 19 | else if (str === "rabbit") { 20 | console.log("A rabbit can bring joy to your home."); 21 | } 22 | }); 23 | console.log("Any of these animals would make a great pet!"); 24 | -------------------------------------------------------------------------------- /Question-60/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // *Question 60:* Self-Running User Profile: Create a quick, 3 | // self-setup profile for a user that can tell you the user's name and age. 4 | function promptUser() { 5 | return new Promise((resolve) => { 6 | const readline = require('readline').createInterface({ 7 | input: process.stdin, 8 | output: process.stdout, 9 | }); 10 | readline.question('What is your name? ', (name) => { 11 | readline.question('What is your age? ', (age) => { 12 | readline.close(); 13 | const parsedAge = parseInt(age); 14 | if (isNaN(parsedAge) || parsedAge < 1) { 15 | console.error('Invalid age entered. Please enter a valid age.'); 16 | process.exit(1); 17 | } 18 | resolve({ name, age: parsedAge }); 19 | }); 20 | }); 21 | }); 22 | } 23 | promptUser().then(({ name, age }) => { 24 | console.log(`Hi, ${name}! You are ${age} years old.`); 25 | }); 26 | -------------------------------------------------------------------------------- /Question-60/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "question-60", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "question-60", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "@types/node": "^20.12.2" 13 | } 14 | }, 15 | "node_modules/@types/node": { 16 | "version": "20.12.2", 17 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.2.tgz", 18 | "integrity": "sha512-zQ0NYO87hyN6Xrclcqp7f8ZbXNbRfoGWNcMvHTPQp9UUrwI0mI7XBz+cu7/W6/VClYo2g63B0cjull/srU7LgQ==", 19 | "dev": true, 20 | "dependencies": { 21 | "undici-types": "~5.26.4" 22 | } 23 | }, 24 | "node_modules/undici-types": { 25 | "version": "5.26.5", 26 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", 27 | "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", 28 | "dev": true 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Question-60/index.ts: -------------------------------------------------------------------------------- 1 | // *Question 60:* Self-Running User Profile: Create a quick, 2 | // self-setup profile for a user that can tell you the user's name and age. 3 | 4 | function promptUser(): Promise<{ name: string, age: number }> { 5 | return new Promise((resolve) => { 6 | const readline = require('readline').createInterface({ 7 | input: process.stdin, 8 | output: process.stdout, 9 | }); 10 | readline.question('What is your name? ', (name: string) => { 11 | readline.question('What is your age? ', (age: string) => { 12 | readline.close(); 13 | const parsedAge = parseInt(age); 14 | if (isNaN(parsedAge) || parsedAge < 1) { 15 | console.error('Invalid age entered. Please enter a valid age.'); 16 | process.exit(1); 17 | } 18 | resolve({ name, age: parsedAge }); 19 | }); 20 | }); 21 | }); 22 | } 23 | promptUser().then(({ name, age }) => { 24 | console.log(`Hi, ${name}! You are ${age} years old.`); 25 | }); -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/mock-pool.d.ts: -------------------------------------------------------------------------------- 1 | import Pool from './pool' 2 | import MockAgent from './mock-agent' 3 | import { Interceptable, MockInterceptor } from './mock-interceptor' 4 | import Dispatcher from './dispatcher' 5 | 6 | export default MockPool 7 | 8 | /** MockPool extends the Pool API and allows one to mock requests. */ 9 | declare class MockPool extends Pool implements Interceptable { 10 | constructor(origin: string, options: MockPool.Options); 11 | /** Intercepts any matching requests that use the same origin as this mock pool. */ 12 | intercept(options: MockInterceptor.Options): MockInterceptor; 13 | /** Dispatches a mocked request. */ 14 | dispatch(options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean; 15 | /** Closes the mock pool and gracefully waits for enqueued requests to complete. */ 16 | close(): Promise; 17 | } 18 | 19 | declare namespace MockPool { 20 | /** MockPool options. */ 21 | export interface Options extends Pool.Options { 22 | /** The agent to associate this MockPool with. */ 23 | agent: MockAgent; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/mock-client.d.ts: -------------------------------------------------------------------------------- 1 | import Client from './client' 2 | import Dispatcher from './dispatcher' 3 | import MockAgent from './mock-agent' 4 | import { MockInterceptor, Interceptable } from './mock-interceptor' 5 | 6 | export default MockClient 7 | 8 | /** MockClient extends the Client API and allows one to mock requests. */ 9 | declare class MockClient extends Client implements Interceptable { 10 | constructor(origin: string, options: MockClient.Options); 11 | /** Intercepts any matching requests that use the same origin as this mock client. */ 12 | intercept(options: MockInterceptor.Options): MockInterceptor; 13 | /** Dispatches a mocked request. */ 14 | dispatch(options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean; 15 | /** Closes the mock client and gracefully waits for enqueued requests to complete. */ 16 | close(): Promise; 17 | } 18 | 19 | declare namespace MockClient { 20 | /** MockClient options. */ 21 | export interface Options extends Client.Options { 22 | /** The agent to associate this MockClient with. */ 23 | agent: MockAgent; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/pool.d.ts: -------------------------------------------------------------------------------- 1 | import Client from './client' 2 | import TPoolStats from './pool-stats' 3 | import { URL } from 'url' 4 | import Dispatcher from "./dispatcher"; 5 | 6 | export default Pool 7 | 8 | declare class Pool extends Dispatcher { 9 | constructor(url: string | URL, options?: Pool.Options) 10 | /** `true` after `pool.close()` has been called. */ 11 | closed: boolean; 12 | /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */ 13 | destroyed: boolean; 14 | /** Aggregate stats for a Pool. */ 15 | readonly stats: TPoolStats; 16 | } 17 | 18 | declare namespace Pool { 19 | export type PoolStats = TPoolStats; 20 | export interface Options extends Client.Options { 21 | /** Default: `(origin, opts) => new Client(origin, opts)`. */ 22 | factory?(origin: URL, opts: object): Dispatcher; 23 | /** The max number of clients to create. `null` if no limit. Default `null`. */ 24 | connections?: number | null; 25 | 26 | interceptors?: { Pool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options["interceptors"] 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/connector.d.ts: -------------------------------------------------------------------------------- 1 | import { TLSSocket, ConnectionOptions } from 'tls' 2 | import { IpcNetConnectOpts, Socket, TcpNetConnectOpts } from 'net' 3 | 4 | export default buildConnector 5 | declare function buildConnector (options?: buildConnector.BuildOptions): buildConnector.connector 6 | 7 | declare namespace buildConnector { 8 | export type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts) & { 9 | allowH2?: boolean; 10 | maxCachedSessions?: number | null; 11 | socketPath?: string | null; 12 | timeout?: number | null; 13 | port?: number; 14 | keepAlive?: boolean | null; 15 | keepAliveInitialDelay?: number | null; 16 | } 17 | 18 | export interface Options { 19 | hostname: string 20 | host?: string 21 | protocol: string 22 | port: string 23 | servername?: string 24 | localAddress?: string | null 25 | httpSocket?: Socket 26 | } 27 | 28 | export type Callback = (...args: CallbackArgs) => void 29 | type CallbackArgs = [null, Socket | TLSSocket] | [Error, null] 30 | 31 | export interface connector { 32 | (options: buildConnector.Options, callback: buildConnector.Callback): void 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/agent.d.ts: -------------------------------------------------------------------------------- 1 | import { URL } from 'url' 2 | import Pool from './pool' 3 | import Dispatcher from "./dispatcher"; 4 | 5 | export default Agent 6 | 7 | declare class Agent extends Dispatcher{ 8 | constructor(opts?: Agent.Options) 9 | /** `true` after `dispatcher.close()` has been called. */ 10 | closed: boolean; 11 | /** `true` after `dispatcher.destroyed()` has been called or `dispatcher.close()` has been called and the dispatcher shutdown has completed. */ 12 | destroyed: boolean; 13 | /** Dispatches a request. */ 14 | dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean; 15 | } 16 | 17 | declare namespace Agent { 18 | export interface Options extends Pool.Options { 19 | /** Default: `(origin, opts) => new Pool(origin, opts)`. */ 20 | factory?(origin: string | URL, opts: Object): Dispatcher; 21 | /** Integer. Default: `0` */ 22 | maxRedirections?: number; 23 | 24 | interceptors?: { Agent?: readonly Dispatcher.DispatchInterceptor[] } & Pool.Options["interceptors"] 25 | } 26 | 27 | export interface DispatchOptions extends Dispatcher.DispatchOptions { 28 | /** Integer. */ 29 | maxRedirections?: number; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /45-Assignment-Q27/main.ts: -------------------------------------------------------------------------------- 1 | // 27. Alien Colors #3: Turn your if-else chain from Exercise 5-4 into an if-else chain. 2 | // • If the alien is green, print a message that the player earned 5 points. 3 | // • If the alien is yellow, print a message that the player earned 10 points. 4 | // • If the alien is red, print a message that the player earned 15 points. 5 | // • Write three versions of this program, making sure each message is printed 6 | // for the appropriate color alien. 7 | 8 | let alienColor1: string = "green"; 9 | if (alienColor1 === "green") { 10 | console.log("player earned 5 points."); 11 | } else if (alienColor1 === "red") { 12 | console.log("player earned 10 points."); 13 | } else { 14 | console.log("player earned 15 points."); 15 | } 16 | alienColor1 = "red" 17 | if (alienColor1 === "green") { 18 | console.log("player earned 5 points."); 19 | } else if (alienColor1 === "red") { 20 | console.log("player earned 10 points."); 21 | } else { 22 | console.log("player earned 15 points."); 23 | } 24 | alienColor1 = "yellow" 25 | if (alienColor1 === "green") { 26 | console.log("player earned 5 points."); 27 | } else if (alienColor1 === "red") { 28 | console.log("player earned 10 points."); 29 | } else { 30 | console.log("player earned 15 points."); 31 | } -------------------------------------------------------------------------------- /45-Assignment-Q28/main.ts: -------------------------------------------------------------------------------- 1 | // 28. Stages of Life: Write an if-else chain that determines a person’s stage of life. 2 | // Set a value for the variable age, and then: 3 | // • If the person is less than 2 years old, print a message that the person is a baby. 4 | // • If the person is at least 2 years old but less than 4, 5 | // print a message that the person is a toddler. 6 | // • If the person is at least 4 years old but less than 13, 7 | // print a message that the person is a kid. 8 | // • If the person is at least 13 years old but less than 20, 9 | // print a message that the person is a teenager. 10 | // • If the person is at least 20 years old but less than 65, 11 | // print a message that the person is an adult. 12 | // • If the person is age 65 or older, print a message that the person is an elder. 13 | 14 | let age: number = 16; 15 | if (age < 2) { 16 | console.log("the person is baby"); 17 | } else if (age >= 2 && age < 4) { 18 | console.log("the person is kid"); 19 | } else if (age >= 4 && age < 13) { 20 | console.log("the person is kid"); 21 | } else if (age >= 13 && age < 20) { 22 | console.log("the person is teeenager"); 23 | } else if (age >= 20 && age < 65) { 24 | console.log("the person is adult"); 25 | } else { 26 | console.log("the person is an elder"); 27 | } -------------------------------------------------------------------------------- /45-Assignment-Q27/main.js: -------------------------------------------------------------------------------- 1 | // 27. Alien Colors #3: Turn your if-else chain from Exercise 5-4 into an if-else chain. 2 | // • If the alien is green, print a message that the player earned 5 points. 3 | // • If the alien is yellow, print a message that the player earned 10 points. 4 | // • If the alien is red, print a message that the player earned 15 points. 5 | // • Write three versions of this program, making sure each message is printed 6 | // for the appropriate color alien. 7 | var alienColor1 = "green"; 8 | if (alienColor1 === "green") { 9 | console.log("player earned 5 points."); 10 | } 11 | else if (alienColor1 === "red") { 12 | console.log("player earned 10 points."); 13 | } 14 | else { 15 | console.log("player earned 15 points."); 16 | } 17 | alienColor1 = "red"; 18 | if (alienColor1 === "green") { 19 | console.log("player earned 5 points."); 20 | } 21 | else if (alienColor1 === "red") { 22 | console.log("player earned 10 points."); 23 | } 24 | else { 25 | console.log("player earned 15 points."); 26 | } 27 | alienColor1 = "yellow"; 28 | if (alienColor1 === "green") { 29 | console.log("player earned 5 points."); 30 | } 31 | else if (alienColor1 === "red") { 32 | console.log("player earned 10 points."); 33 | } 34 | else { 35 | console.log("player earned 15 points."); 36 | } 37 | -------------------------------------------------------------------------------- /45-Assignment-Q28/main.js: -------------------------------------------------------------------------------- 1 | // 28. Stages of Life: Write an if-else chain that determines a person’s stage of life. 2 | // Set a value for the variable age, and then: 3 | // • If the person is less than 2 years old, print a message that the person is a baby. 4 | // • If the person is at least 2 years old but less than 4, 5 | // print a message that the person is a toddler. 6 | // • If the person is at least 4 years old but less than 13, 7 | // print a message that the person is a kid. 8 | // • If the person is at least 13 years old but less than 20, 9 | // print a message that the person is a teenager. 10 | // • If the person is at least 20 years old but less than 65, 11 | // print a message that the person is an adult. 12 | // • If the person is age 65 or older, print a message that the person is an elder. 13 | var age = 16; 14 | if (age < 2) { 15 | console.log("the person is baby"); 16 | } 17 | else if (age >= 2 && age < 4) { 18 | console.log("the person is kid"); 19 | } 20 | else if (age >= 4 && age < 13) { 21 | console.log("the person is kid"); 22 | } 23 | else if (age >= 13 && age < 20) { 24 | console.log("the person is teeenager"); 25 | } 26 | else if (age >= 20 && age < 65) { 27 | console.log("the person is adult"); 28 | } 29 | else { 30 | console.log("the person is an elder"); 31 | } 32 | -------------------------------------------------------------------------------- /45-Assignment-Q43/main.ts: -------------------------------------------------------------------------------- 1 | // 43. Unchanged Magicians: Start with your work from Exercise 40. Call the 2 | // function make_great() with a copy of the array of magicians’ names. Because the 3 | // original array will be unchanged, return the new array and store it in a separate array. 4 | // Call show_magicians() with each array to show that you have one array of the original 5 | // names and one array with the Great added to each magician’s name. 6 | 7 | // Define an array of magicians' names 8 | let magicins: string[] = ["Harry Houdini", "David Copperfield", "Penn Jillette", "Teller"]; 9 | 10 | // Function to add "Great" to each magician's name 11 | function makeGreat(names: string[]): string[] { 12 | let greatMagicians: string[] = []; 13 | for (let name of names) { 14 | greatMagicians.push("Great " + name); 15 | } 16 | return greatMagicians; 17 | } 18 | 19 | // Function to show the list of magicians 20 | function showMagicians(names: string[]): void { 21 | for (let name of names) { 22 | console.log(name); 23 | } 24 | } 25 | 26 | // Call makeGreat() with a copy of the original array 27 | let greatMagicians = makeGreat([...magicins]); 28 | 29 | // Call showMagicians() with both arrays 30 | console.log("Original Magicians:"); 31 | showMagicians(magicins); 32 | console.log("Great Magicians:"); 33 | showMagicians(greatMagicians); -------------------------------------------------------------------------------- /45-Assignment-Q17/main.ts: -------------------------------------------------------------------------------- 1 | // 17. Shrinking Guest List: You just found out that your new dinner table won’t arrive in time for the dinner, 2 | // and you have space for only two guests. 3 | 4 | // • Start with your program from Exercise 16. 5 | // Add a new line that prints a message saying that you can invite only two people for dinner. 6 | 7 | // • Remove guests from your list one at a time until only two names remain in your list. 8 | // Each time you pop a name from your list, print a message to that person letting them know 9 | // I am sorry I can’t invite You to dinner. 10 | 11 | // • Print a message to each of the two people still on your list, letting them know they’re still invited. 12 | 13 | // • Remove the last two names from your list, so you have an empty list. 14 | // Print your list to make sure you actually have an empty list at the end of your program. 15 | 16 | let guestArr: string[] = ["Anoosha", "Umar", "Ubaid", "Warisha", "Hamza", "Umaima"]; 17 | let message: string = "sorry You can’t invited to a dinner."; 18 | while (guestArr.length > 2) { 19 | let removeGuest = guestArr.pop(); 20 | console.log(`Dear ${removeGuest} ${message}`); 21 | } 22 | 23 | for (let val of guestArr) { 24 | console.log(`Dear ${val} You Are Still Invited To A Dinner.`); 25 | } 26 | 27 | guestArr.splice(0,2); 28 | console.log(guestArr); 29 | -------------------------------------------------------------------------------- /45-Assignment-Q17/main.js: -------------------------------------------------------------------------------- 1 | // 17. Shrinking Guest List: You just found out that your new dinner table won’t arrive in time for the dinner, 2 | // and you have space for only two guests. 3 | // • Start with your program from Exercise 16. 4 | // Add a new line that prints a message saying that you can invite only two people for dinner. 5 | // • Remove guests from your list one at a time until only two names remain in your list. 6 | // Each time you pop a name from your list, print a message to that person letting them know 7 | // I am sorry I can’t invite You to dinner. 8 | // • Print a message to each of the two people still on your list, letting them know they’re still invited. 9 | // • Remove the last two names from your list, so you have an empty list. 10 | // Print your list to make sure you actually have an empty list at the end of your program. 11 | var guestArr = ["Anoosha", "Umar", "Ubaid", "Warisha", "Hamza", "Umaima"]; 12 | var message = "sorry You can’t invited to a dinner."; 13 | while (guestArr.length > 2) { 14 | var removeGuest = guestArr.pop(); 15 | console.log("Dear ".concat(removeGuest, " ").concat(message)); 16 | } 17 | for (var _i = 0, guestArr_1 = guestArr; _i < guestArr_1.length; _i++) { 18 | var val = guestArr_1[_i]; 19 | console.log("Dear ".concat(val, " You Are Still Invited To A Dinner.")); 20 | } 21 | guestArr.splice(0, 2); 22 | console.log(guestArr); 23 | -------------------------------------------------------------------------------- /45-Assignment-Q40/main.ts: -------------------------------------------------------------------------------- 1 | // 40. Album: Write a function called make_album() that builds a Object 2 | // describing a music album. The function should take in an artist name and an 3 | // album title, and it should return a Object containing these two pieces of 4 | // information. Use the function to make three dictionaries representing different 5 | // albums. Print each return value to show that Objects are storing the 6 | // album information correctly. 7 | // Add an optional parameter to make_album() that allows you to store the 8 | // number of tracks on an album. If the calling line includes a value for the number 9 | // of tracks, add that value to the album’s Object. Make at least one new 10 | // function call that includes the number of tracks on an album. 11 | interface Album { 12 | artist: string; 13 | title: string; 14 | tracks?: number; 15 | } 16 | 17 | function make_album(artist: string, title: string, tracks?: number): Album { 18 | const album: Album = { 19 | artist: artist, 20 | title: title, 21 | }; 22 | 23 | if (tracks) { 24 | album.tracks = tracks; 25 | } 26 | 27 | return album; 28 | } 29 | const album1 = make_album("The Beatles", "Abbey Road"); 30 | console.log(album1); 31 | const album2 = make_album("Michael Jackson", "Thriller"); 32 | console.log(album2); 33 | const album3 = make_album("Queen", "A Night at the Opera", 14); 34 | console.log(album3); -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/cache.d.ts: -------------------------------------------------------------------------------- 1 | import type { RequestInfo, Response, Request } from './fetch' 2 | 3 | export interface CacheStorage { 4 | match (request: RequestInfo, options?: MultiCacheQueryOptions): Promise, 5 | has (cacheName: string): Promise, 6 | open (cacheName: string): Promise, 7 | delete (cacheName: string): Promise, 8 | keys (): Promise 9 | } 10 | 11 | declare const CacheStorage: { 12 | prototype: CacheStorage 13 | new(): CacheStorage 14 | } 15 | 16 | export interface Cache { 17 | match (request: RequestInfo, options?: CacheQueryOptions): Promise, 18 | matchAll (request?: RequestInfo, options?: CacheQueryOptions): Promise, 19 | add (request: RequestInfo): Promise, 20 | addAll (requests: RequestInfo[]): Promise, 21 | put (request: RequestInfo, response: Response): Promise, 22 | delete (request: RequestInfo, options?: CacheQueryOptions): Promise, 23 | keys (request?: RequestInfo, options?: CacheQueryOptions): Promise 24 | } 25 | 26 | export interface CacheQueryOptions { 27 | ignoreSearch?: boolean, 28 | ignoreMethod?: boolean, 29 | ignoreVary?: boolean 30 | } 31 | 32 | export interface MultiCacheQueryOptions extends CacheQueryOptions { 33 | cacheName?: string 34 | } 35 | 36 | export declare const caches: CacheStorage 37 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "undici-types", 3 | "version": "5.26.5", 4 | "description": "A stand-alone types package for Undici", 5 | "homepage": "https://undici.nodejs.org", 6 | "bugs": { 7 | "url": "https://github.com/nodejs/undici/issues" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/nodejs/undici.git" 12 | }, 13 | "license": "MIT", 14 | "types": "index.d.ts", 15 | "files": [ 16 | "*.d.ts" 17 | ], 18 | "contributors": [ 19 | { 20 | "name": "Daniele Belardi", 21 | "url": "https://github.com/dnlup", 22 | "author": true 23 | }, 24 | { 25 | "name": "Ethan Arrowood", 26 | "url": "https://github.com/ethan-arrowood", 27 | "author": true 28 | }, 29 | { 30 | "name": "Matteo Collina", 31 | "url": "https://github.com/mcollina", 32 | "author": true 33 | }, 34 | { 35 | "name": "Matthew Aitken", 36 | "url": "https://github.com/KhafraDev", 37 | "author": true 38 | }, 39 | { 40 | "name": "Robert Nagy", 41 | "url": "https://github.com/ronag", 42 | "author": true 43 | }, 44 | { 45 | "name": "Szymon Marczak", 46 | "url": "https://github.com/szmarczak", 47 | "author": true 48 | }, 49 | { 50 | "name": "Tomas Della Vedova", 51 | "url": "https://github.com/delvedor", 52 | "author": true 53 | } 54 | ] 55 | } -------------------------------------------------------------------------------- /45-Assignment-Q32/main.ts: -------------------------------------------------------------------------------- 1 | // 32. Checking Usernames: Do the following to create a program that simulates 2 | // how websites ensure that everyone has a unique username. 3 | // • Make a list of five or more usernames called current_users. 4 | // • Make another list of five usernames called new_users. 5 | // Make sure one or two of the new usernames are also in the current_users list. 6 | // • Loop through the new_users list to see if each new username has already been used. 7 | // If it has, print a message that the person will need to enter a 8 | // new username. If a username has not been used, 9 | // print a message saying that the username is available. 10 | 11 | // • Make a list of five or more usernames called current_users. 12 | 13 | let current_users: string[] = ["john", "alice", "mary", "alice", "jenny"]; 14 | // • Make another list of five usernames called new_users. 15 | let new_users: string[] = ["peter", "john", "jerry", "alice", "susan"]; 16 | // • Loop through the new_users 17 | for (let new_user of new_users) { 18 | // If it has, print a message that the person will need to enter a 19 | // new username. If a username has not been used, 20 | if (current_users.includes(new_user)) { 21 | console.log(`The username ${new_user} is already taken. please enter a new username.`); 22 | } else { 23 | // If a username has not been used, 24 | // print a message saying that the username is available. 25 | console.log(`The username ${new_user} is available.`); 26 | } 27 | } -------------------------------------------------------------------------------- /45-Assignment-Q16/main.ts: -------------------------------------------------------------------------------- 1 | // 16. More Guests: You just found a bigger dinner table, so now more space is 2 | // available. Think of three more guests to invite to dinner. 3 | 4 | // • Start with your program from Exercise 15. Add a print statement to the end of your 5 | // bigger dinner table. program informing people that you found a 6 | 7 | // • Add one new guest to the beginning of your array. 8 | // • Add one new guest to the middle of your array. 9 | // • Use append() to add one new guest to the end of your list. 10 | // • Print a new set of invitation messages, one for each person in your list. 11 | 12 | let guestArr: string[] = ["Ubaid", "Warisha", "Shahnawaz", "Umar", "Anoosha"]; 13 | let cannotAttend: string = "Shahnawaz"; 14 | let newGuest: string = "Umaima"; 15 | guestArr[guestArr.indexOf(cannotAttend)] = newGuest; 16 | // • Add one new guest to the beginning of your array. 17 | let beginningGuest: string = "Touqeer"; 18 | guestArr.unshift(beginningGuest); 19 | // • Add one new guest to the middle of your array. 20 | let middleGuest: string = "Hamza"; 21 | let middleIndex = guestArr.length / 2; 22 | guestArr.splice(middleIndex, 0, middleGuest); 23 | // • Use append() to add one new guest to the end of your list. 24 | let lastGuest: string = "Ayesha"; 25 | guestArr.push(lastGuest); 26 | // • Print a new set of invitation messages, one for each person in your list. 27 | let message: string = "You Are Invited For Special Dinner At Special Place On Special Day" 28 | for (let val of guestArr) { 29 | console.log(`Dear ${val} ${message}`); 30 | } 31 | -------------------------------------------------------------------------------- /45-Assignment-Q16/main.js: -------------------------------------------------------------------------------- 1 | // 16. More Guests: You just found a bigger dinner table, so now more space is 2 | // available. Think of three more guests to invite to dinner. 3 | // • Start with your program from Exercise 15. Add a print statement to the end of your 4 | // bigger dinner table. program informing people that you found a 5 | // • Add one new guest to the beginning of your array. 6 | // • Add one new guest to the middle of your array. 7 | // • Use append() to add one new guest to the end of your list. 8 | // • Print a new set of invitation messages, one for each person in your list. 9 | var guestArr = ["Ubaid", "Warisha", "Shahnawaz", "Umar", "Anoosha"]; 10 | var cannotAttend = "Shahnawaz"; 11 | var newGuest = "Umaima"; 12 | guestArr[guestArr.indexOf(cannotAttend)] = newGuest; 13 | // • Add one new guest to the beginning of your array. 14 | var beginningGuest = "Touqeer"; 15 | guestArr.unshift(beginningGuest); 16 | // • Add one new guest to the middle of your array. 17 | var middleGuest = "Hamza"; 18 | var middleIndex = guestArr.length / 2; 19 | guestArr.splice(middleIndex, 0, middleGuest); 20 | // • Use append() to add one new guest to the end of your list. 21 | var lastGuest = "Ayesha"; 22 | guestArr.push(lastGuest); 23 | // • Print a new set of invitation messages, one for each person in your list. 24 | var message = "You Are Invited For Special Dinner At Special Place On Special Day"; 25 | for (var _i = 0, guestArr_1 = guestArr; _i < guestArr_1.length; _i++) { 26 | var val = guestArr_1[_i]; 27 | console.log("Dear ".concat(val, " ").concat(message)); 28 | } 29 | -------------------------------------------------------------------------------- /45-Assignment-Q32/main.js: -------------------------------------------------------------------------------- 1 | // 32. Checking Usernames: Do the following to create a program that simulates 2 | // how websites ensure that everyone has a unique username. 3 | // • Make a list of five or more usernames called current_users. 4 | // • Make another list of five usernames called new_users. 5 | // Make sure one or two of the new usernames are also in the current_users list. 6 | // • Loop through the new_users list to see if each new username has already been used. 7 | // If it has, print a message that the person will need to enter a 8 | // new username. If a username has not been used, 9 | // print a message saying that the username is available. 10 | // • Make a list of five or more usernames called current_users. 11 | var current_users = ["john", "alice", "mary", "alice", "jenny"]; 12 | // • Make another list of five usernames called new_users. 13 | var new_users = ["peter", "john", "jerry", "alice", "susan"]; 14 | // • Loop through the new_users 15 | for (var _i = 0, new_users_1 = new_users; _i < new_users_1.length; _i++) { 16 | var new_user = new_users_1[_i]; 17 | // If it has, print a message that the person will need to enter a 18 | // new username. If a username has not been used, 19 | if (current_users.includes(new_user)) { 20 | console.log("The username ".concat(new_user, " is already taken. please enter a new username.")); 21 | } 22 | else { 23 | // If a username has not been used, 24 | // print a message saying that the username is available. 25 | console.log("The username ".concat(new_user, " is available.")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /45-Assignment-Q15/main.ts: -------------------------------------------------------------------------------- 1 | // 15. Changing Guest List: You just heard that one of your guests can’t make the 2 | // dinner, so you need to send out a new set of invitations. You’ll have to think of 3 | // someone else to invite. 4 | 5 | // • Start with your program from Exercise 14. Add a print statement at the 6 | // end of your program stating the name of the guest who can’t make it. 7 | 8 | // • Modify your list, replacing the name of the guest who can’t make it with 9 | // the name of the new person you are inviting. 10 | 11 | // • Print a second set of invitation messages, one for each person who is still 12 | // in your list. 13 | 14 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 15 | 16 | // • Start with your program from Exercise 14. Add a print statement at the 17 | // end of your program stating the name of the guest who can’t make it. 18 | 19 | let guestArr: string[] = ["Ubaid", "Warisha", "Shahnawaz", "Umar", "Anoosha"]; 20 | let cannotAttend: string = "Shahnawaz"; 21 | console.log(`${cannotAttend} cannot make it, for Dinner`); 22 | 23 | // • Modify your list, replacing the name of the guest who can’t make it with 24 | // the name of the new person you are inviting. 25 | 26 | let newGuest: string = "Hamza"; 27 | guestArr[guestArr.indexOf(cannotAttend)] = newGuest; 28 | 29 | // • Print a second set of invitation messages, one for each person who is still 30 | // in your list. 31 | 32 | let message: string = "You Are invited to a Special Dinner"; 33 | for (let val of guestArr){ 34 | console.log(`Dear ${val} ${message}`); 35 | } -------------------------------------------------------------------------------- /45-Assignment-Q15/main.js: -------------------------------------------------------------------------------- 1 | // 15. Changing Guest List: You just heard that one of your guests can’t make the 2 | // dinner, so you need to send out a new set of invitations. You’ll have to think of 3 | // someone else to invite. 4 | // • Start with your program from Exercise 14. Add a print statement at the 5 | // end of your program stating the name of the guest who can’t make it. 6 | // • Modify your list, replacing the name of the guest who can’t make it with 7 | // the name of the new person you are inviting. 8 | // • Print a second set of invitation messages, one for each person who is still 9 | // in your list. 10 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 11 | // • Start with your program from Exercise 14. Add a print statement at the 12 | // end of your program stating the name of the guest who can’t make it. 13 | var guestArr = ["Ubaid", "Warisha", "Shahnawaz", "Umar", "Anoosha"]; 14 | var cannotAttend = "Shahnawaz"; 15 | console.log("".concat(cannotAttend, " cannot make it, for Dinner")); 16 | // • Modify your list, replacing the name of the guest who can’t make it with 17 | // the name of the new person you are inviting. 18 | var newGuest = "Hamza"; 19 | guestArr[guestArr.indexOf(cannotAttend)] = newGuest; 20 | // • Print a second set of invitation messages, one for each person who is still 21 | // in your list. 22 | var message = "You Are invited to a Special Dinner"; 23 | for (var _i = 0, guestArr_1 = guestArr; _i < guestArr_1.length; _i++) { 24 | var val = guestArr_1[_i]; 25 | console.log("Dear ".concat(val, " ").concat(message)); 26 | } 27 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/api.d.ts: -------------------------------------------------------------------------------- 1 | import { URL, UrlObject } from 'url' 2 | import { Duplex } from 'stream' 3 | import Dispatcher from './dispatcher' 4 | 5 | export { 6 | request, 7 | stream, 8 | pipeline, 9 | connect, 10 | upgrade, 11 | } 12 | 13 | /** Performs an HTTP request. */ 14 | declare function request( 15 | url: string | URL | UrlObject, 16 | options?: { dispatcher?: Dispatcher } & Omit & Partial>, 17 | ): Promise; 18 | 19 | /** A faster version of `request`. */ 20 | declare function stream( 21 | url: string | URL | UrlObject, 22 | options: { dispatcher?: Dispatcher } & Omit, 23 | factory: Dispatcher.StreamFactory 24 | ): Promise; 25 | 26 | /** For easy use with `stream.pipeline`. */ 27 | declare function pipeline( 28 | url: string | URL | UrlObject, 29 | options: { dispatcher?: Dispatcher } & Omit, 30 | handler: Dispatcher.PipelineHandler 31 | ): Duplex; 32 | 33 | /** Starts two-way communications with the requested resource. */ 34 | declare function connect( 35 | url: string | URL | UrlObject, 36 | options?: { dispatcher?: Dispatcher } & Omit 37 | ): Promise; 38 | 39 | /** Upgrade to a different protocol. */ 40 | declare function upgrade( 41 | url: string | URL | UrlObject, 42 | options?: { dispatcher?: Dispatcher } & Omit 43 | ): Promise; 44 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/filereader.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Blob } from 'buffer' 4 | import { DOMException, Event, EventInit, EventTarget } from './patch' 5 | 6 | export declare class FileReader { 7 | __proto__: EventTarget & FileReader 8 | 9 | constructor () 10 | 11 | readAsArrayBuffer (blob: Blob): void 12 | readAsBinaryString (blob: Blob): void 13 | readAsText (blob: Blob, encoding?: string): void 14 | readAsDataURL (blob: Blob): void 15 | 16 | abort (): void 17 | 18 | static readonly EMPTY = 0 19 | static readonly LOADING = 1 20 | static readonly DONE = 2 21 | 22 | readonly EMPTY = 0 23 | readonly LOADING = 1 24 | readonly DONE = 2 25 | 26 | readonly readyState: number 27 | 28 | readonly result: string | ArrayBuffer | null 29 | 30 | readonly error: DOMException | null 31 | 32 | onloadstart: null | ((this: FileReader, event: ProgressEvent) => void) 33 | onprogress: null | ((this: FileReader, event: ProgressEvent) => void) 34 | onload: null | ((this: FileReader, event: ProgressEvent) => void) 35 | onabort: null | ((this: FileReader, event: ProgressEvent) => void) 36 | onerror: null | ((this: FileReader, event: ProgressEvent) => void) 37 | onloadend: null | ((this: FileReader, event: ProgressEvent) => void) 38 | } 39 | 40 | export interface ProgressEventInit extends EventInit { 41 | lengthComputable?: boolean 42 | loaded?: number 43 | total?: number 44 | } 45 | 46 | export declare class ProgressEvent { 47 | __proto__: Event & ProgressEvent 48 | 49 | constructor (type: string, eventInitDict?: ProgressEventInit) 50 | 51 | readonly lengthComputable: boolean 52 | readonly loaded: number 53 | readonly total: number 54 | } 55 | -------------------------------------------------------------------------------- /45-Assignment-Q23/main.js: -------------------------------------------------------------------------------- 1 | // 23. Conditional Tests: Write a series of conditional tests. Print a statement 2 | // describing each test and your prediction for the results of each test. Your code 3 | // should look something like this: 4 | // let car = 'subaru'; 5 | // console.log("Is car == 'subaru'? I predict True.") 6 | // console.log(car == 'subaru') 7 | // • Look closely at your results, and make sure you understand why each line evaluates to 8 | // True or False. 9 | // • Create at least 10 tests. Have at least 5 tests evaluate to True and another 10 | // 5 tests evaluate to False. 11 | var car = "Bugatti"; 12 | console.log("Is car == 'Bugatti' I Predict True"); 13 | console.log(car == "Bugatti"); 14 | var country = "Pakistan"; 15 | console.log("Is country == 'Pakistan' I Predict True"); 16 | console.log(country == "Pakistan"); 17 | var pizza = "Large"; 18 | console.log("Is pizza == 'Large' I Predict True"); 19 | console.log(pizza == "Large"); 20 | var paper = "Maths"; 21 | console.log("Is paper == 'Maths' I Predict True"); 22 | console.log(paper == "Maths"); 23 | var chocolate = "Dairymilk"; 24 | console.log("Is chocolate == 'Dairymilk' I Predict True"); 25 | console.log(chocolate == "Dairymilk"); 26 | car = "Konisegg"; 27 | console.log("Is car == 'Bugatti' I Predict False"); 28 | console.log(car == "Bugatti"); 29 | country = "India"; 30 | console.log("Is country == 'Pakistan' I Predict False"); 31 | console.log(country == "Pakistan"); 32 | pizza = "small"; 33 | console.log("Is pizza == 'Large' I Predict False"); 34 | console.log(pizza == "Large"); 35 | paper = "English"; 36 | console.log("Is paper == 'Maths' I Predict False"); 37 | console.log(paper == "Maths"); 38 | chocolate = "Kitkat"; 39 | console.log("Is chocolate == 'Dairymilk' I Predict False"); 40 | console.log(chocolate == "Dairymilk"); 41 | -------------------------------------------------------------------------------- /45-Assignment-Q43/main.js: -------------------------------------------------------------------------------- 1 | // 43. Unchanged Magicians: Start with your work from Exercise 40. Call the 2 | // function make_great() with a copy of the array of magicians’ names. Because the 3 | // original array will be unchanged, return the new array and store it in a separate array. 4 | // Call show_magicians() with each array to show that you have one array of the original 5 | // names and one array with the Great added to each magician’s name. 6 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { 7 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 8 | if (ar || !(i in from)) { 9 | if (!ar) ar = Array.prototype.slice.call(from, 0, i); 10 | ar[i] = from[i]; 11 | } 12 | } 13 | return to.concat(ar || Array.prototype.slice.call(from)); 14 | }; 15 | // Define an array of magicians' names 16 | var magicins = ["Harry Houdini", "David Copperfield", "Penn Jillette", "Teller"]; 17 | // Function to add "Great" to each magician's name 18 | function makeGreat(names) { 19 | var greatMagicians = []; 20 | for (var _i = 0, names_1 = names; _i < names_1.length; _i++) { 21 | var name_1 = names_1[_i]; 22 | greatMagicians.push("Great " + name_1); 23 | } 24 | return greatMagicians; 25 | } 26 | // Function to show the list of magicians 27 | function showMagicians(names) { 28 | for (var _i = 0, names_2 = names; _i < names_2.length; _i++) { 29 | var name_2 = names_2[_i]; 30 | console.log(name_2); 31 | } 32 | } 33 | // Call makeGreat() with a copy of the original array 34 | var greatMagicians = makeGreat(__spreadArray([], magicins, true)); 35 | // Call showMagicians() with both arrays 36 | console.log("Original Magicians:"); 37 | showMagicians(magicins); 38 | console.log("Great Magicians:"); 39 | showMagicians(greatMagicians); 40 | -------------------------------------------------------------------------------- /45-Assignment-Q23/main.ts: -------------------------------------------------------------------------------- 1 | // 23. Conditional Tests: Write a series of conditional tests. Print a statement 2 | // describing each test and your prediction for the results of each test. Your code 3 | // should look something like this: 4 | 5 | // let car = 'subaru'; 6 | 7 | // console.log("Is car == 'subaru'? I predict True.") 8 | 9 | // console.log(car == 'subaru') 10 | 11 | // • Look closely at your results, and make sure you understand why each line evaluates to 12 | // True or False. 13 | 14 | // • Create at least 10 tests. Have at least 5 tests evaluate to True and another 15 | // 5 tests evaluate to False. 16 | 17 | let car: string = "Bugatti"; 18 | console.log("Is car == 'Bugatti' I Predict True"); 19 | console.log(car == "Bugatti"); 20 | let country: string = "Pakistan"; 21 | console.log("Is country == 'Pakistan' I Predict True"); 22 | console.log(country == "Pakistan"); 23 | let pizza: string = "Large"; 24 | console.log("Is pizza == 'Large' I Predict True"); 25 | console.log(pizza == "Large"); 26 | let paper: string = "Maths"; 27 | console.log("Is paper == 'Maths' I Predict True"); 28 | console.log(paper == "Maths"); 29 | let chocolate: string = "Dairymilk"; 30 | console.log("Is chocolate == 'Dairymilk' I Predict True"); 31 | console.log(chocolate == "Dairymilk"); 32 | car = "Konisegg"; 33 | console.log("Is car == 'Bugatti' I Predict False"); 34 | console.log(car == "Bugatti"); 35 | country = "India"; 36 | console.log("Is country == 'Pakistan' I Predict False"); 37 | console.log(country == "Pakistan"); 38 | pizza = "small"; 39 | console.log("Is pizza == 'Large' I Predict False"); 40 | console.log(pizza == "Large"); 41 | paper = "English"; 42 | console.log("Is paper == 'Maths' I Predict False"); 43 | console.log(paper == "Maths"); 44 | chocolate = "Kitkat"; 45 | console.log("Is chocolate == 'Dairymilk' I Predict False"); 46 | console.log(chocolate == "Dairymilk"); -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/file.d.ts: -------------------------------------------------------------------------------- 1 | // Based on https://github.com/octet-stream/form-data/blob/2d0f0dc371517444ce1f22cdde13f51995d0953a/lib/File.ts (MIT) 2 | /// 3 | 4 | import { Blob } from 'buffer' 5 | 6 | export interface BlobPropertyBag { 7 | type?: string 8 | endings?: 'native' | 'transparent' 9 | } 10 | 11 | export interface FilePropertyBag extends BlobPropertyBag { 12 | /** 13 | * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date. 14 | */ 15 | lastModified?: number 16 | } 17 | 18 | export declare class File extends Blob { 19 | /** 20 | * Creates a new File instance. 21 | * 22 | * @param fileBits An `Array` strings, or [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), [`ArrayBufferView`](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects, or a mix of any of such objects, that will be put inside the [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). 23 | * @param fileName The name of the file. 24 | * @param options An options object containing optional attributes for the file. 25 | */ 26 | constructor(fileBits: ReadonlyArray, fileName: string, options?: FilePropertyBag) 27 | 28 | /** 29 | * Name of the file referenced by the File object. 30 | */ 31 | readonly name: string 32 | 33 | /** 34 | * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date. 35 | */ 36 | readonly lastModified: number 37 | 38 | readonly [Symbol.toStringTag]: string 39 | } 40 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/readable.d.ts: -------------------------------------------------------------------------------- 1 | import { Readable } from "stream"; 2 | import { Blob } from 'buffer' 3 | 4 | export default BodyReadable 5 | 6 | declare class BodyReadable extends Readable { 7 | constructor( 8 | resume?: (this: Readable, size: number) => void | null, 9 | abort?: () => void | null, 10 | contentType?: string 11 | ) 12 | 13 | /** Consumes and returns the body as a string 14 | * https://fetch.spec.whatwg.org/#dom-body-text 15 | */ 16 | text(): Promise 17 | 18 | /** Consumes and returns the body as a JavaScript Object 19 | * https://fetch.spec.whatwg.org/#dom-body-json 20 | */ 21 | json(): Promise 22 | 23 | /** Consumes and returns the body as a Blob 24 | * https://fetch.spec.whatwg.org/#dom-body-blob 25 | */ 26 | blob(): Promise 27 | 28 | /** Consumes and returns the body as an ArrayBuffer 29 | * https://fetch.spec.whatwg.org/#dom-body-arraybuffer 30 | */ 31 | arrayBuffer(): Promise 32 | 33 | /** Not implemented 34 | * 35 | * https://fetch.spec.whatwg.org/#dom-body-formdata 36 | */ 37 | formData(): Promise 38 | 39 | /** Returns true if the body is not null and the body has been consumed 40 | * 41 | * Otherwise, returns false 42 | * 43 | * https://fetch.spec.whatwg.org/#dom-body-bodyused 44 | */ 45 | readonly bodyUsed: boolean 46 | 47 | /** Throws on node 16.6.0 48 | * 49 | * If body is null, it should return null as the body 50 | * 51 | * If body is not null, should return the body as a ReadableStream 52 | * 53 | * https://fetch.spec.whatwg.org/#dom-body-body 54 | */ 55 | readonly body: never | undefined 56 | 57 | /** Dumps the response body by reading `limit` number of bytes. 58 | * @param opts.limit Number of bytes to read (optional) - Default: 262144 59 | */ 60 | dump(opts?: { limit: number }): Promise 61 | } 62 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/diagnostics-channel.d.ts: -------------------------------------------------------------------------------- 1 | import { Socket } from "net"; 2 | import { URL } from "url"; 3 | import Connector from "./connector"; 4 | import Dispatcher from "./dispatcher"; 5 | 6 | declare namespace DiagnosticsChannel { 7 | interface Request { 8 | origin?: string | URL; 9 | completed: boolean; 10 | method?: Dispatcher.HttpMethod; 11 | path: string; 12 | headers: string; 13 | addHeader(key: string, value: string): Request; 14 | } 15 | interface Response { 16 | statusCode: number; 17 | statusText: string; 18 | headers: Array; 19 | } 20 | type Error = unknown; 21 | interface ConnectParams { 22 | host: URL["host"]; 23 | hostname: URL["hostname"]; 24 | protocol: URL["protocol"]; 25 | port: URL["port"]; 26 | servername: string | null; 27 | } 28 | type Connector = Connector.connector; 29 | export interface RequestCreateMessage { 30 | request: Request; 31 | } 32 | export interface RequestBodySentMessage { 33 | request: Request; 34 | } 35 | export interface RequestHeadersMessage { 36 | request: Request; 37 | response: Response; 38 | } 39 | export interface RequestTrailersMessage { 40 | request: Request; 41 | trailers: Array; 42 | } 43 | export interface RequestErrorMessage { 44 | request: Request; 45 | error: Error; 46 | } 47 | export interface ClientSendHeadersMessage { 48 | request: Request; 49 | headers: string; 50 | socket: Socket; 51 | } 52 | export interface ClientBeforeConnectMessage { 53 | connectParams: ConnectParams; 54 | connector: Connector; 55 | } 56 | export interface ClientConnectedMessage { 57 | socket: Socket; 58 | connectParams: ConnectParams; 59 | connector: Connector; 60 | } 61 | export interface ClientConnectErrorMessage { 62 | error: Error; 63 | socket: Socket; 64 | connectParams: ConnectParams; 65 | connector: Connector; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /45-Assignment-Q24/main.js: -------------------------------------------------------------------------------- 1 | // 24. More Conditional Tests: You don’t have to limit the number of tests you create to 10. 2 | // If you want to try more comparisons, write more tests. 3 | // Have at least one True and one False result for each of the following: 4 | // • Tests for equality and inequality with strings 5 | // • Tests using the lower case function 6 | // • Numerical tests involving equality and inequality, greater than and less than, 7 | // greater than or equal to, and less than or equal to 8 | // • Tests using "and" and "or" operators 9 | // • Test whether an item is in a array 10 | // • Test whether an item is not in a array 11 | // • Tests for equality and inequality with strings 12 | var str1 = "Hello"; 13 | var str2 = "Hello"; 14 | console.log(str1 === str2); // True 15 | console.log(str1 !== str2); // false 16 | // • Tests using the lower case function 17 | var str3 = "HELLO"; 18 | console.log(str3.toLowerCase() !== str3); // true 19 | console.log(str3.toLowerCase() === str3); // false 20 | // • Numerical tests involving equality and inequality, greater than and less than, 21 | // greater than or equal to, and less than or equal to. 22 | var num1 = 10; 23 | var num2 = 15; 24 | console.log(num1 !== num2); // true 25 | console.log(num1 === num2); // false 26 | console.log(num1 < num2); // true 27 | console.log(num1 > num2); // false 28 | console.log(num1 <= num2); // true 29 | console.log(num1 >= num2); // false 30 | // • Tests using "and" and "or" operators 31 | var x = 15; 32 | var y = 20; 33 | // && 34 | console.log(x > 0 && y <= 20); // true 35 | console.log(x > 0 && y < 0); // false 36 | // || 37 | console.log(x > 0 || y <= 20); // true 38 | console.log(x < 0 || y < 0); // false 39 | // • Test whether an item is in a array 40 | var arr = [1, 2, 3, 4, 5]; 41 | var checkItem = 3; 42 | console.log(arr.includes(checkItem)); // true 43 | // • Test whether an item is not in a array 44 | var arr2 = [1, 2, 3, 4, 5]; 45 | var checkItem2 = 6; 46 | console.log(arr.includes(checkItem2)); // true 47 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/patch.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://github.com/nodejs/undici/issues/1740 4 | 5 | export type DOMException = typeof globalThis extends { DOMException: infer T } 6 | ? T 7 | : any 8 | 9 | export type EventTarget = typeof globalThis extends { EventTarget: infer T } 10 | ? T 11 | : { 12 | addEventListener( 13 | type: string, 14 | listener: any, 15 | options?: any, 16 | ): void 17 | dispatchEvent(event: Event): boolean 18 | removeEventListener( 19 | type: string, 20 | listener: any, 21 | options?: any | boolean, 22 | ): void 23 | } 24 | 25 | export type Event = typeof globalThis extends { Event: infer T } 26 | ? T 27 | : { 28 | readonly bubbles: boolean 29 | cancelBubble: () => void 30 | readonly cancelable: boolean 31 | readonly composed: boolean 32 | composedPath(): [EventTarget?] 33 | readonly currentTarget: EventTarget | null 34 | readonly defaultPrevented: boolean 35 | readonly eventPhase: 0 | 2 36 | readonly isTrusted: boolean 37 | preventDefault(): void 38 | returnValue: boolean 39 | readonly srcElement: EventTarget | null 40 | stopImmediatePropagation(): void 41 | stopPropagation(): void 42 | readonly target: EventTarget | null 43 | readonly timeStamp: number 44 | readonly type: string 45 | } 46 | 47 | export interface EventInit { 48 | bubbles?: boolean 49 | cancelable?: boolean 50 | composed?: boolean 51 | } 52 | 53 | export interface EventListenerOptions { 54 | capture?: boolean 55 | } 56 | 57 | export interface AddEventListenerOptions extends EventListenerOptions { 58 | once?: boolean 59 | passive?: boolean 60 | signal?: AbortSignal 61 | } 62 | 63 | export type EventListenerOrEventListenerObject = EventListener | EventListenerObject 64 | 65 | export interface EventListenerObject { 66 | handleEvent (object: Event): void 67 | } 68 | 69 | export interface EventListener { 70 | (evt: Event): void 71 | } 72 | -------------------------------------------------------------------------------- /45-Assignment-Q24/main.ts: -------------------------------------------------------------------------------- 1 | // 24. More Conditional Tests: You don’t have to limit the number of tests you create to 10. 2 | // If you want to try more comparisons, write more tests. 3 | // Have at least one True and one False result for each of the following: 4 | // • Tests for equality and inequality with strings 5 | // • Tests using the lower case function 6 | // • Numerical tests involving equality and inequality, greater than and less than, 7 | // greater than or equal to, and less than or equal to 8 | // • Tests using "and" and "or" operators 9 | // • Test whether an item is in a array 10 | // • Test whether an item is not in a array 11 | 12 | 13 | // • Tests for equality and inequality with strings 14 | 15 | let str1: string = "Hello"; 16 | let str2: string = "Hello"; 17 | console.log(str1 === str2); // True 18 | console.log(str1 !== str2); // false 19 | 20 | // • Tests using the lower case function 21 | 22 | let str3: string = "HELLO"; 23 | console.log(str3.toLowerCase() !== str3); // true 24 | console.log(str3.toLowerCase() === str3); // false 25 | 26 | // • Numerical tests involving equality and inequality, greater than and less than, 27 | // greater than or equal to, and less than or equal to. 28 | 29 | let num1: number = 10; 30 | let num2: number = 15; 31 | console.log(num1 !== num2); // true 32 | console.log(num1 === num2); // false 33 | console.log(num1 < num2); // true 34 | console.log(num1 > num2); // false 35 | console.log(num1 <= num2); // true 36 | console.log(num1 >= num2); // false 37 | 38 | // • Tests using "and" and "or" operators 39 | 40 | let x: number = 15; 41 | let y: number = 20; 42 | 43 | // && 44 | console.log(x > 0 && y <= 20); // true 45 | console.log(x > 0 && y < 0); // false 46 | 47 | // || 48 | console.log(x > 0 || y <= 20); // true 49 | console.log(x < 0 || y < 0); // false 50 | 51 | // • Test whether an item is in a array 52 | 53 | let arr: number[] = [1, 2, 3, 4, 5]; 54 | let checkItem: number = 3; 55 | console.log(arr.includes(checkItem)); // true 56 | 57 | // • Test whether an item is not in a array 58 | 59 | let arr2: number[] = [1, 2, 3, 4, 5]; 60 | let checkItem2: number = 6; 61 | console.log(arr.includes(checkItem2)); // true 62 | -------------------------------------------------------------------------------- /45-Assignment-Q18/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // 18. Seeing the World: Think of at least five places in the world you’d like to visit. 3 | // • Store the locations in a array. Make sure the array is not in alphabetical order. 4 | // • Print your array in its original order. 5 | // • Print your array in alphabetical order without modifying the actual list. 6 | // • Show that your array is still in its original order by printing it. 7 | // • Print your array in reverse alphabetical order without changing the order of the original list. 8 | // • Show that your array is still in its original order by printing it again. 9 | // • Reverse the order of your list. Print the array to show that its 10 | // order has changed. 11 | // • Reverse the order of your list again. Print the list to show it’s back to its original order. 12 | // • Sort your array so it’s stored in alphabetical order. Print the array to show that its order has been changed. 13 | // • Sort to change your array so it’s stored in reverse alphabetical order. Print the list to show that its order has changed. 14 | // Step 1: Countries to Visit: 15 | let visitCountries = ["Turkey", "London", "Saudia Arabia", "Switzerland", "Maldives"]; 16 | // Step 2: In Original Order: 17 | console.log(visitCountries); 18 | // Step 3: In Alphabetical Order: 19 | console.log([...visitCountries].sort()); 20 | // Step 4: Array still in its Original Order: 21 | console.log(visitCountries); 22 | // Step 5: Reverse the Order of list: 23 | console.log([...visitCountries].sort().reverse()); 24 | // Step 6: Back to it's Original Order: 25 | console.log(visitCountries); 26 | // Step 7: Reverse the Order of List: 27 | visitCountries.reverse(); 28 | console.log(visitCountries); 29 | // Step 8: Reverse the Order of your List Again and Bring Back to its Original control: 30 | visitCountries.reverse(); 31 | console.log(visitCountries); 32 | // Step 9: Sort the Array in an Alphabetical Order: 33 | visitCountries.sort(); 34 | console.log(visitCountries); 35 | // Step 10: Sort to Change an Array in Reverse Alphabetical Order: 36 | let sortedArray = [ 37 | "Turkey", "London", "Saudia Arabia", "Switzerland", "Maldives", 38 | ]; 39 | sortedArray.sort(); 40 | console.log(sortedArray); 41 | sortedArray.reverse(); 42 | console.log(sortedArray); 43 | -------------------------------------------------------------------------------- /45-Assignment-Q18/main.ts: -------------------------------------------------------------------------------- 1 | // 18. Seeing the World: Think of at least five places in the world you’d like to visit. 2 | // • Store the locations in a array. Make sure the array is not in alphabetical order. 3 | // • Print your array in its original order. 4 | // • Print your array in alphabetical order without modifying the actual list. 5 | // • Show that your array is still in its original order by printing it. 6 | // • Print your array in reverse alphabetical order without changing the order of the original list. 7 | // • Show that your array is still in its original order by printing it again. 8 | // • Reverse the order of your list. Print the array to show that its 9 | // order has changed. 10 | // • Reverse the order of your list again. Print the list to show it’s back to its original order. 11 | // • Sort your array so it’s stored in alphabetical order. Print the array to show that its order has been changed. 12 | // • Sort to change your array so it’s stored in reverse alphabetical order. Print the list to show that its order has changed. 13 | 14 | 15 | // Step 1: Countries to Visit: 16 | let visitCountries: string[] = ["Turkey", "London", "Saudia Arabia", "Switzerland", "Maldives"]; 17 | // Step 2: In Original Order: 18 | console.log(visitCountries); 19 | // Step 3: In Alphabetical Order: 20 | console.log([...visitCountries].sort()); 21 | // Step 4: Array still in its Original Order: 22 | console.log(visitCountries); 23 | // Step 5: Reverse the Order of list: 24 | console.log([...visitCountries].sort().reverse()); 25 | // Step 6: Back to it's Original Order: 26 | console.log(visitCountries); 27 | // Step 7: Reverse the Order of List: 28 | visitCountries.reverse(); 29 | console.log(visitCountries); 30 | // Step 8: Reverse the Order of your List Again and Bring Back to its Original control: 31 | visitCountries.reverse(); 32 | console.log(visitCountries); 33 | // Step 9: Sort the Array in an Alphabetical Order: 34 | visitCountries.sort(); 35 | console.log(visitCountries); 36 | // Step 10: Sort to Change an Array in Reverse Alphabetical Order: 37 | let sortedArray = [ 38 | "Turkey", "London", "Saudia Arabia", "Switzerland", "Maldives", 39 | ]; 40 | sortedArray.sort(); 41 | console.log(sortedArray); 42 | sortedArray.reverse(); 43 | console.log(sortedArray); 44 | 45 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/README.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | > `npm install --save @types/node` 3 | 4 | # Summary 5 | This package contains type definitions for node (https://nodejs.org/). 6 | 7 | # Details 8 | Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node. 9 | 10 | ### Additional Details 11 | * Last updated: Sat, 30 Mar 2024 05:35:18 GMT 12 | * Dependencies: [undici-types](https://npmjs.com/package/undici-types) 13 | 14 | # Credits 15 | These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [Yongsheng Zhang](https://github.com/ZYSzys), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky). 16 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/mock-agent.d.ts: -------------------------------------------------------------------------------- 1 | import Agent from './agent' 2 | import Dispatcher from './dispatcher' 3 | import { Interceptable, MockInterceptor } from './mock-interceptor' 4 | import MockDispatch = MockInterceptor.MockDispatch; 5 | 6 | export default MockAgent 7 | 8 | interface PendingInterceptor extends MockDispatch { 9 | origin: string; 10 | } 11 | 12 | /** A mocked Agent class that implements the Agent API. It allows one to intercept HTTP requests made through undici and return mocked responses instead. */ 13 | declare class MockAgent extends Dispatcher { 14 | constructor(options?: MockAgent.Options) 15 | /** Creates and retrieves mock Dispatcher instances which can then be used to intercept HTTP requests. If the number of connections on the mock agent is set to 1, a MockClient instance is returned. Otherwise a MockPool instance is returned. */ 16 | get(origin: string): TInterceptable; 17 | get(origin: RegExp): TInterceptable; 18 | get(origin: ((origin: string) => boolean)): TInterceptable; 19 | /** Dispatches a mocked request. */ 20 | dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean; 21 | /** Closes the mock agent and waits for registered mock pools and clients to also close before resolving. */ 22 | close(): Promise; 23 | /** Disables mocking in MockAgent. */ 24 | deactivate(): void; 25 | /** Enables mocking in a MockAgent instance. When instantiated, a MockAgent is automatically activated. Therefore, this method is only effective after `MockAgent.deactivate` has been called. */ 26 | activate(): void; 27 | /** Define host matchers so only matching requests that aren't intercepted by the mock dispatchers will be attempted. */ 28 | enableNetConnect(): void; 29 | enableNetConnect(host: string): void; 30 | enableNetConnect(host: RegExp): void; 31 | enableNetConnect(host: ((host: string) => boolean)): void; 32 | /** Causes all requests to throw when requests are not matched in a MockAgent intercept. */ 33 | disableNetConnect(): void; 34 | pendingInterceptors(): PendingInterceptor[]; 35 | assertNoPendingInterceptors(options?: { 36 | pendingInterceptorsFormatter?: PendingInterceptorsFormatter; 37 | }): void; 38 | } 39 | 40 | interface PendingInterceptorsFormatter { 41 | format(pendingInterceptors: readonly PendingInterceptor[]): string; 42 | } 43 | 44 | declare namespace MockAgent { 45 | /** MockAgent options. */ 46 | export interface Options extends Agent.Options { 47 | /** A custom agent to be encapsulated by the MockAgent. */ 48 | agent?: Agent; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/stream/promises.d.ts: -------------------------------------------------------------------------------- 1 | declare module "stream/promises" { 2 | import { 3 | FinishedOptions, 4 | PipelineDestination, 5 | PipelineOptions, 6 | PipelinePromise, 7 | PipelineSource, 8 | PipelineTransform, 9 | } from "node:stream"; 10 | function finished( 11 | stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, 12 | options?: FinishedOptions, 13 | ): Promise; 14 | function pipeline, B extends PipelineDestination>( 15 | source: A, 16 | destination: B, 17 | options?: PipelineOptions, 18 | ): PipelinePromise; 19 | function pipeline< 20 | A extends PipelineSource, 21 | T1 extends PipelineTransform, 22 | B extends PipelineDestination, 23 | >( 24 | source: A, 25 | transform1: T1, 26 | destination: B, 27 | options?: PipelineOptions, 28 | ): PipelinePromise; 29 | function pipeline< 30 | A extends PipelineSource, 31 | T1 extends PipelineTransform, 32 | T2 extends PipelineTransform, 33 | B extends PipelineDestination, 34 | >( 35 | source: A, 36 | transform1: T1, 37 | transform2: T2, 38 | destination: B, 39 | options?: PipelineOptions, 40 | ): PipelinePromise; 41 | function pipeline< 42 | A extends PipelineSource, 43 | T1 extends PipelineTransform, 44 | T2 extends PipelineTransform, 45 | T3 extends PipelineTransform, 46 | B extends PipelineDestination, 47 | >( 48 | source: A, 49 | transform1: T1, 50 | transform2: T2, 51 | transform3: T3, 52 | destination: B, 53 | options?: PipelineOptions, 54 | ): PipelinePromise; 55 | function pipeline< 56 | A extends PipelineSource, 57 | T1 extends PipelineTransform, 58 | T2 extends PipelineTransform, 59 | T3 extends PipelineTransform, 60 | T4 extends PipelineTransform, 61 | B extends PipelineDestination, 62 | >( 63 | source: A, 64 | transform1: T1, 65 | transform2: T2, 66 | transform3: T3, 67 | transform4: T4, 68 | destination: B, 69 | options?: PipelineOptions, 70 | ): PipelinePromise; 71 | function pipeline( 72 | streams: ReadonlyArray, 73 | options?: PipelineOptions, 74 | ): Promise; 75 | function pipeline( 76 | stream1: NodeJS.ReadableStream, 77 | stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream, 78 | ...streams: Array 79 | ): Promise; 80 | } 81 | declare module "node:stream/promises" { 82 | export * from "stream/promises"; 83 | } 84 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/string_decoder.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The `node:string_decoder` module provides an API for decoding `Buffer` objects 3 | * into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 4 | * characters. It can be accessed using: 5 | * 6 | * ```js 7 | * const { StringDecoder } = require('node:string_decoder'); 8 | * ``` 9 | * 10 | * The following example shows the basic use of the `StringDecoder` class. 11 | * 12 | * ```js 13 | * const { StringDecoder } = require('node:string_decoder'); 14 | * const decoder = new StringDecoder('utf8'); 15 | * 16 | * const cent = Buffer.from([0xC2, 0xA2]); 17 | * console.log(decoder.write(cent)); // Prints: ¢ 18 | * 19 | * const euro = Buffer.from([0xE2, 0x82, 0xAC]); 20 | * console.log(decoder.write(euro)); // Prints: € 21 | * ``` 22 | * 23 | * When a `Buffer` instance is written to the `StringDecoder` instance, an 24 | * internal buffer is used to ensure that the decoded string does not contain 25 | * any incomplete multibyte characters. These are held in the buffer until the 26 | * next call to `stringDecoder.write()` or until `stringDecoder.end()` is called. 27 | * 28 | * In the following example, the three UTF-8 encoded bytes of the European Euro 29 | * symbol (`€`) are written over three separate operations: 30 | * 31 | * ```js 32 | * const { StringDecoder } = require('node:string_decoder'); 33 | * const decoder = new StringDecoder('utf8'); 34 | * 35 | * decoder.write(Buffer.from([0xE2])); 36 | * decoder.write(Buffer.from([0x82])); 37 | * console.log(decoder.end(Buffer.from([0xAC]))); // Prints: € 38 | * ``` 39 | * @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/string_decoder.js) 40 | */ 41 | declare module "string_decoder" { 42 | class StringDecoder { 43 | constructor(encoding?: BufferEncoding); 44 | /** 45 | * Returns a decoded string, ensuring that any incomplete multibyte characters at 46 | * the end of the `Buffer`, or `TypedArray`, or `DataView` are omitted from the 47 | * returned string and stored in an internal buffer for the next call to`stringDecoder.write()` or `stringDecoder.end()`. 48 | * @since v0.1.99 49 | * @param buffer The bytes to decode. 50 | */ 51 | write(buffer: string | Buffer | NodeJS.ArrayBufferView): string; 52 | /** 53 | * Returns any remaining input stored in the internal buffer as a string. Bytes 54 | * representing incomplete UTF-8 and UTF-16 characters will be replaced with 55 | * substitution characters appropriate for the character encoding. 56 | * 57 | * If the `buffer` argument is provided, one final call to `stringDecoder.write()`is performed before returning the remaining input. 58 | * After `end()` is called, the `stringDecoder` object can be reused for new input. 59 | * @since v0.9.3 60 | * @param buffer The bytes to decode. 61 | */ 62 | end(buffer?: string | Buffer | NodeJS.ArrayBufferView): string; 63 | } 64 | } 65 | declare module "node:string_decoder" { 66 | export * from "string_decoder"; 67 | } 68 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/index.d.ts: -------------------------------------------------------------------------------- 1 | import Dispatcher from'./dispatcher' 2 | import { setGlobalDispatcher, getGlobalDispatcher } from './global-dispatcher' 3 | import { setGlobalOrigin, getGlobalOrigin } from './global-origin' 4 | import Pool from'./pool' 5 | import { RedirectHandler, DecoratorHandler } from './handlers' 6 | 7 | import BalancedPool from './balanced-pool' 8 | import Client from'./client' 9 | import buildConnector from'./connector' 10 | import errors from'./errors' 11 | import Agent from'./agent' 12 | import MockClient from'./mock-client' 13 | import MockPool from'./mock-pool' 14 | import MockAgent from'./mock-agent' 15 | import mockErrors from'./mock-errors' 16 | import ProxyAgent from'./proxy-agent' 17 | import { request, pipeline, stream, connect, upgrade } from './api' 18 | 19 | export * from './cookies' 20 | export * from './fetch' 21 | export * from './file' 22 | export * from './filereader' 23 | export * from './formdata' 24 | export * from './diagnostics-channel' 25 | export * from './websocket' 26 | export * from './content-type' 27 | export * from './cache' 28 | export { Interceptable } from './mock-interceptor' 29 | 30 | export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler } 31 | export default Undici 32 | 33 | declare namespace Undici { 34 | var Dispatcher: typeof import('./dispatcher').default 35 | var Pool: typeof import('./pool').default; 36 | var RedirectHandler: typeof import ('./handlers').RedirectHandler 37 | var DecoratorHandler: typeof import ('./handlers').DecoratorHandler 38 | var createRedirectInterceptor: typeof import ('./interceptors').createRedirectInterceptor 39 | var BalancedPool: typeof import('./balanced-pool').default; 40 | var Client: typeof import('./client').default; 41 | var buildConnector: typeof import('./connector').default; 42 | var errors: typeof import('./errors').default; 43 | var Agent: typeof import('./agent').default; 44 | var setGlobalDispatcher: typeof import('./global-dispatcher').setGlobalDispatcher; 45 | var getGlobalDispatcher: typeof import('./global-dispatcher').getGlobalDispatcher; 46 | var request: typeof import('./api').request; 47 | var stream: typeof import('./api').stream; 48 | var pipeline: typeof import('./api').pipeline; 49 | var connect: typeof import('./api').connect; 50 | var upgrade: typeof import('./api').upgrade; 51 | var MockClient: typeof import('./mock-client').default; 52 | var MockPool: typeof import('./mock-pool').default; 53 | var MockAgent: typeof import('./mock-agent').default; 54 | var mockErrors: typeof import('./mock-errors').default; 55 | var fetch: typeof import('./fetch').fetch; 56 | var Headers: typeof import('./fetch').Headers; 57 | var Response: typeof import('./fetch').Response; 58 | var Request: typeof import('./fetch').Request; 59 | var FormData: typeof import('./formdata').FormData; 60 | var File: typeof import('./file').File; 61 | var FileReader: typeof import('./filereader').FileReader; 62 | var caches: typeof import('./cache').caches; 63 | } 64 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/timers/promises.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The `timers/promises` API provides an alternative set of timer functions 3 | * that return `Promise` objects. The API is accessible via`require('node:timers/promises')`. 4 | * 5 | * ```js 6 | * import { 7 | * setTimeout, 8 | * setImmediate, 9 | * setInterval, 10 | * } from 'timers/promises'; 11 | * ``` 12 | * @since v15.0.0 13 | */ 14 | declare module "timers/promises" { 15 | import { TimerOptions } from "node:timers"; 16 | /** 17 | * ```js 18 | * import { 19 | * setTimeout, 20 | * } from 'timers/promises'; 21 | * 22 | * const res = await setTimeout(100, 'result'); 23 | * 24 | * console.log(res); // Prints 'result' 25 | * ``` 26 | * @since v15.0.0 27 | * @param [delay=1] The number of milliseconds to wait before fulfilling the promise. 28 | * @param value A value with which the promise is fulfilled. 29 | */ 30 | function setTimeout(delay?: number, value?: T, options?: TimerOptions): Promise; 31 | /** 32 | * ```js 33 | * import { 34 | * setImmediate, 35 | * } from 'timers/promises'; 36 | * 37 | * const res = await setImmediate('result'); 38 | * 39 | * console.log(res); // Prints 'result' 40 | * ``` 41 | * @since v15.0.0 42 | * @param value A value with which the promise is fulfilled. 43 | */ 44 | function setImmediate(value?: T, options?: TimerOptions): Promise; 45 | /** 46 | * Returns an async iterator that generates values in an interval of `delay` ms. 47 | * If `ref` is `true`, you need to call `next()` of async iterator explicitly 48 | * or implicitly to keep the event loop alive. 49 | * 50 | * ```js 51 | * import { 52 | * setInterval, 53 | * } from 'timers/promises'; 54 | * 55 | * const interval = 100; 56 | * for await (const startTime of setInterval(interval, Date.now())) { 57 | * const now = Date.now(); 58 | * console.log(now); 59 | * if ((now - startTime) > 1000) 60 | * break; 61 | * } 62 | * console.log(Date.now()); 63 | * ``` 64 | * @since v15.9.0 65 | */ 66 | function setInterval(delay?: number, value?: T, options?: TimerOptions): AsyncIterable; 67 | interface Scheduler { 68 | /** 69 | * ```js 70 | * import { scheduler } from 'node:timers/promises'; 71 | * 72 | * await scheduler.wait(1000); // Wait one second before continuing 73 | * ``` 74 | * An experimental API defined by the Scheduling APIs draft specification being developed as a standard Web Platform API. 75 | * Calling timersPromises.scheduler.wait(delay, options) is roughly equivalent to calling timersPromises.setTimeout(delay, undefined, options) except that the ref option is not supported. 76 | * @since v16.14.0 77 | * @experimental 78 | * @param [delay=1] The number of milliseconds to wait before fulfilling the promise. 79 | */ 80 | wait: (delay?: number, options?: TimerOptions) => Promise; 81 | /** 82 | * An experimental API defined by the Scheduling APIs draft specification being developed as a standard Web Platform API. 83 | * Calling timersPromises.scheduler.yield() is equivalent to calling timersPromises.setImmediate() with no arguments. 84 | * @since v16.14.0 85 | * @experimental 86 | */ 87 | yield: () => Promise; 88 | } 89 | const scheduler: Scheduler; 90 | } 91 | declare module "node:timers/promises" { 92 | export * from "timers/promises"; 93 | } 94 | -------------------------------------------------------------------------------- /Question-60/node_modules/@types/node/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * License for programmatically and manually incorporated 3 | * documentation aka. `JSDoc` from https://github.com/nodejs/node/tree/master/doc 4 | * 5 | * Copyright Node.js contributors. All rights reserved. 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 | * IN THE SOFTWARE. 23 | */ 24 | 25 | // NOTE: These definitions support NodeJS and TypeScript 4.9+. 26 | 27 | // Reference required types from the default lib: 28 | /// 29 | /// 30 | /// 31 | /// 32 | 33 | // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: 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 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/websocket.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import type { Blob } from 'buffer' 4 | import type { MessagePort } from 'worker_threads' 5 | import { 6 | EventTarget, 7 | Event, 8 | EventInit, 9 | EventListenerOptions, 10 | AddEventListenerOptions, 11 | EventListenerOrEventListenerObject 12 | } from './patch' 13 | import Dispatcher from './dispatcher' 14 | import { HeadersInit } from './fetch' 15 | 16 | export type BinaryType = 'blob' | 'arraybuffer' 17 | 18 | interface WebSocketEventMap { 19 | close: CloseEvent 20 | error: Event 21 | message: MessageEvent 22 | open: Event 23 | } 24 | 25 | interface WebSocket extends EventTarget { 26 | binaryType: BinaryType 27 | 28 | readonly bufferedAmount: number 29 | readonly extensions: string 30 | 31 | onclose: ((this: WebSocket, ev: WebSocketEventMap['close']) => any) | null 32 | onerror: ((this: WebSocket, ev: WebSocketEventMap['error']) => any) | null 33 | onmessage: ((this: WebSocket, ev: WebSocketEventMap['message']) => any) | null 34 | onopen: ((this: WebSocket, ev: WebSocketEventMap['open']) => any) | null 35 | 36 | readonly protocol: string 37 | readonly readyState: number 38 | readonly url: string 39 | 40 | close(code?: number, reason?: string): void 41 | send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void 42 | 43 | readonly CLOSED: number 44 | readonly CLOSING: number 45 | readonly CONNECTING: number 46 | readonly OPEN: number 47 | 48 | addEventListener( 49 | type: K, 50 | listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, 51 | options?: boolean | AddEventListenerOptions 52 | ): void 53 | addEventListener( 54 | type: string, 55 | listener: EventListenerOrEventListenerObject, 56 | options?: boolean | AddEventListenerOptions 57 | ): void 58 | removeEventListener( 59 | type: K, 60 | listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, 61 | options?: boolean | EventListenerOptions 62 | ): void 63 | removeEventListener( 64 | type: string, 65 | listener: EventListenerOrEventListenerObject, 66 | options?: boolean | EventListenerOptions 67 | ): void 68 | } 69 | 70 | export declare const WebSocket: { 71 | prototype: WebSocket 72 | new (url: string | URL, protocols?: string | string[] | WebSocketInit): WebSocket 73 | readonly CLOSED: number 74 | readonly CLOSING: number 75 | readonly CONNECTING: number 76 | readonly OPEN: number 77 | } 78 | 79 | interface CloseEventInit extends EventInit { 80 | code?: number 81 | reason?: string 82 | wasClean?: boolean 83 | } 84 | 85 | interface CloseEvent extends Event { 86 | readonly code: number 87 | readonly reason: string 88 | readonly wasClean: boolean 89 | } 90 | 91 | export declare const CloseEvent: { 92 | prototype: CloseEvent 93 | new (type: string, eventInitDict?: CloseEventInit): CloseEvent 94 | } 95 | 96 | interface MessageEventInit extends EventInit { 97 | data?: T 98 | lastEventId?: string 99 | origin?: string 100 | ports?: (typeof MessagePort)[] 101 | source?: typeof MessagePort | null 102 | } 103 | 104 | interface MessageEvent extends Event { 105 | readonly data: T 106 | readonly lastEventId: string 107 | readonly origin: string 108 | readonly ports: ReadonlyArray 109 | readonly source: typeof MessagePort | null 110 | initMessageEvent( 111 | type: string, 112 | bubbles?: boolean, 113 | cancelable?: boolean, 114 | data?: any, 115 | origin?: string, 116 | lastEventId?: string, 117 | source?: typeof MessagePort | null, 118 | ports?: (typeof MessagePort)[] 119 | ): void; 120 | } 121 | 122 | export declare const MessageEvent: { 123 | prototype: MessageEvent 124 | new(type: string, eventInitDict?: MessageEventInit): MessageEvent 125 | } 126 | 127 | interface WebSocketInit { 128 | protocols?: string | string[], 129 | dispatcher?: Dispatcher, 130 | headers?: HeadersInit 131 | } 132 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/mock-interceptor.d.ts: -------------------------------------------------------------------------------- 1 | import { IncomingHttpHeaders } from './header' 2 | import Dispatcher from './dispatcher'; 3 | import { BodyInit, Headers } from './fetch' 4 | 5 | export { 6 | Interceptable, 7 | MockInterceptor, 8 | MockScope 9 | } 10 | 11 | /** The scope associated with a mock dispatch. */ 12 | declare class MockScope { 13 | constructor(mockDispatch: MockInterceptor.MockDispatch); 14 | /** Delay a reply by a set amount of time in ms. */ 15 | delay(waitInMs: number): MockScope; 16 | /** Persist the defined mock data for the associated reply. It will return the defined mock data indefinitely. */ 17 | persist(): MockScope; 18 | /** Define a reply for a set amount of matching requests. */ 19 | times(repeatTimes: number): MockScope; 20 | } 21 | 22 | /** The interceptor for a Mock. */ 23 | declare class MockInterceptor { 24 | constructor(options: MockInterceptor.Options, mockDispatches: MockInterceptor.MockDispatch[]); 25 | /** Mock an undici request with the defined reply. */ 26 | reply(replyOptionsCallback: MockInterceptor.MockReplyOptionsCallback): MockScope; 27 | reply( 28 | statusCode: number, 29 | data?: TData | Buffer | string | MockInterceptor.MockResponseDataHandler, 30 | responseOptions?: MockInterceptor.MockResponseOptions 31 | ): MockScope; 32 | /** Mock an undici request by throwing the defined reply error. */ 33 | replyWithError(error: TError): MockScope; 34 | /** Set default reply headers on the interceptor for subsequent mocked replies. */ 35 | defaultReplyHeaders(headers: IncomingHttpHeaders): MockInterceptor; 36 | /** Set default reply trailers on the interceptor for subsequent mocked replies. */ 37 | defaultReplyTrailers(trailers: Record): MockInterceptor; 38 | /** Set automatically calculated content-length header on subsequent mocked replies. */ 39 | replyContentLength(): MockInterceptor; 40 | } 41 | 42 | declare namespace MockInterceptor { 43 | /** MockInterceptor options. */ 44 | export interface Options { 45 | /** Path to intercept on. */ 46 | path: string | RegExp | ((path: string) => boolean); 47 | /** Method to intercept on. Defaults to GET. */ 48 | method?: string | RegExp | ((method: string) => boolean); 49 | /** Body to intercept on. */ 50 | body?: string | RegExp | ((body: string) => boolean); 51 | /** Headers to intercept on. */ 52 | headers?: Record boolean)> | ((headers: Record) => boolean); 53 | /** Query params to intercept on */ 54 | query?: Record; 55 | } 56 | export interface MockDispatch extends Options { 57 | times: number | null; 58 | persist: boolean; 59 | consumed: boolean; 60 | data: MockDispatchData; 61 | } 62 | export interface MockDispatchData extends MockResponseOptions { 63 | error: TError | null; 64 | statusCode?: number; 65 | data?: TData | string; 66 | } 67 | export interface MockResponseOptions { 68 | headers?: IncomingHttpHeaders; 69 | trailers?: Record; 70 | } 71 | 72 | export interface MockResponseCallbackOptions { 73 | path: string; 74 | origin: string; 75 | method: string; 76 | body?: BodyInit | Dispatcher.DispatchOptions['body']; 77 | headers: Headers | Record; 78 | maxRedirections: number; 79 | } 80 | 81 | export type MockResponseDataHandler = ( 82 | opts: MockResponseCallbackOptions 83 | ) => TData | Buffer | string; 84 | 85 | export type MockReplyOptionsCallback = ( 86 | opts: MockResponseCallbackOptions 87 | ) => { statusCode: number, data?: TData | Buffer | string, responseOptions?: MockResponseOptions } 88 | } 89 | 90 | interface Interceptable extends Dispatcher { 91 | /** Intercepts any matching requests that use the same origin as this mock client. */ 92 | intercept(options: MockInterceptor.Options): MockInterceptor; 93 | } 94 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/errors.d.ts: -------------------------------------------------------------------------------- 1 | import { IncomingHttpHeaders } from "./header"; 2 | import Client from './client' 3 | 4 | export default Errors 5 | 6 | declare namespace Errors { 7 | export class UndiciError extends Error { 8 | name: string; 9 | code: string; 10 | } 11 | 12 | /** Connect timeout error. */ 13 | export class ConnectTimeoutError extends UndiciError { 14 | name: 'ConnectTimeoutError'; 15 | code: 'UND_ERR_CONNECT_TIMEOUT'; 16 | } 17 | 18 | /** A header exceeds the `headersTimeout` option. */ 19 | export class HeadersTimeoutError extends UndiciError { 20 | name: 'HeadersTimeoutError'; 21 | code: 'UND_ERR_HEADERS_TIMEOUT'; 22 | } 23 | 24 | /** Headers overflow error. */ 25 | export class HeadersOverflowError extends UndiciError { 26 | name: 'HeadersOverflowError' 27 | code: 'UND_ERR_HEADERS_OVERFLOW' 28 | } 29 | 30 | /** A body exceeds the `bodyTimeout` option. */ 31 | export class BodyTimeoutError extends UndiciError { 32 | name: 'BodyTimeoutError'; 33 | code: 'UND_ERR_BODY_TIMEOUT'; 34 | } 35 | 36 | export class ResponseStatusCodeError extends UndiciError { 37 | constructor ( 38 | message?: string, 39 | statusCode?: number, 40 | headers?: IncomingHttpHeaders | string[] | null, 41 | body?: null | Record | string 42 | ); 43 | name: 'ResponseStatusCodeError'; 44 | code: 'UND_ERR_RESPONSE_STATUS_CODE'; 45 | body: null | Record | string 46 | status: number 47 | statusCode: number 48 | headers: IncomingHttpHeaders | string[] | null; 49 | } 50 | 51 | /** Passed an invalid argument. */ 52 | export class InvalidArgumentError extends UndiciError { 53 | name: 'InvalidArgumentError'; 54 | code: 'UND_ERR_INVALID_ARG'; 55 | } 56 | 57 | /** Returned an invalid value. */ 58 | export class InvalidReturnValueError extends UndiciError { 59 | name: 'InvalidReturnValueError'; 60 | code: 'UND_ERR_INVALID_RETURN_VALUE'; 61 | } 62 | 63 | /** The request has been aborted by the user. */ 64 | export class RequestAbortedError extends UndiciError { 65 | name: 'AbortError'; 66 | code: 'UND_ERR_ABORTED'; 67 | } 68 | 69 | /** Expected error with reason. */ 70 | export class InformationalError extends UndiciError { 71 | name: 'InformationalError'; 72 | code: 'UND_ERR_INFO'; 73 | } 74 | 75 | /** Request body length does not match content-length header. */ 76 | export class RequestContentLengthMismatchError extends UndiciError { 77 | name: 'RequestContentLengthMismatchError'; 78 | code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'; 79 | } 80 | 81 | /** Response body length does not match content-length header. */ 82 | export class ResponseContentLengthMismatchError extends UndiciError { 83 | name: 'ResponseContentLengthMismatchError'; 84 | code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH'; 85 | } 86 | 87 | /** Trying to use a destroyed client. */ 88 | export class ClientDestroyedError extends UndiciError { 89 | name: 'ClientDestroyedError'; 90 | code: 'UND_ERR_DESTROYED'; 91 | } 92 | 93 | /** Trying to use a closed client. */ 94 | export class ClientClosedError extends UndiciError { 95 | name: 'ClientClosedError'; 96 | code: 'UND_ERR_CLOSED'; 97 | } 98 | 99 | /** There is an error with the socket. */ 100 | export class SocketError extends UndiciError { 101 | name: 'SocketError'; 102 | code: 'UND_ERR_SOCKET'; 103 | socket: Client.SocketInfo | null 104 | } 105 | 106 | /** Encountered unsupported functionality. */ 107 | export class NotSupportedError extends UndiciError { 108 | name: 'NotSupportedError'; 109 | code: 'UND_ERR_NOT_SUPPORTED'; 110 | } 111 | 112 | /** No upstream has been added to the BalancedPool. */ 113 | export class BalancedPoolMissingUpstreamError extends UndiciError { 114 | name: 'MissingUpstreamError'; 115 | code: 'UND_ERR_BPL_MISSING_UPSTREAM'; 116 | } 117 | 118 | export class HTTPParserError extends UndiciError { 119 | name: 'HTTPParserError'; 120 | code: string; 121 | } 122 | 123 | /** The response exceed the length allowed. */ 124 | export class ResponseExceededMaxSizeError extends UndiciError { 125 | name: 'ResponseExceededMaxSizeError'; 126 | code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE'; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Question-60/node_modules/undici-types/client.d.ts: -------------------------------------------------------------------------------- 1 | import { URL } from 'url' 2 | import { TlsOptions } from 'tls' 3 | import Dispatcher from './dispatcher' 4 | import buildConnector from "./connector"; 5 | 6 | /** 7 | * A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default. 8 | */ 9 | export class Client extends Dispatcher { 10 | constructor(url: string | URL, options?: Client.Options); 11 | /** Property to get and set the pipelining factor. */ 12 | pipelining: number; 13 | /** `true` after `client.close()` has been called. */ 14 | closed: boolean; 15 | /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */ 16 | destroyed: boolean; 17 | } 18 | 19 | export declare namespace Client { 20 | export interface OptionsInterceptors { 21 | Client: readonly Dispatcher.DispatchInterceptor[]; 22 | } 23 | export interface Options { 24 | /** TODO */ 25 | interceptors?: OptionsInterceptors; 26 | /** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */ 27 | maxHeaderSize?: number; 28 | /** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */ 29 | headersTimeout?: number; 30 | /** @deprecated unsupported socketTimeout, use headersTimeout & bodyTimeout instead */ 31 | socketTimeout?: never; 32 | /** @deprecated unsupported requestTimeout, use headersTimeout & bodyTimeout instead */ 33 | requestTimeout?: never; 34 | /** TODO */ 35 | connectTimeout?: number; 36 | /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */ 37 | bodyTimeout?: number; 38 | /** @deprecated unsupported idleTimeout, use keepAliveTimeout instead */ 39 | idleTimeout?: never; 40 | /** @deprecated unsupported keepAlive, use pipelining=0 instead */ 41 | keepAlive?: never; 42 | /** the timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. Default: `4e3` milliseconds (4s). */ 43 | keepAliveTimeout?: number; 44 | /** @deprecated unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead */ 45 | maxKeepAliveTimeout?: never; 46 | /** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */ 47 | keepAliveMaxTimeout?: number; 48 | /** A number of milliseconds subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */ 49 | keepAliveTimeoutThreshold?: number; 50 | /** TODO */ 51 | socketPath?: string; 52 | /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */ 53 | pipelining?: number; 54 | /** @deprecated use the connect option instead */ 55 | tls?: never; 56 | /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */ 57 | strictContentLength?: boolean; 58 | /** TODO */ 59 | maxCachedSessions?: number; 60 | /** TODO */ 61 | maxRedirections?: number; 62 | /** TODO */ 63 | connect?: buildConnector.BuildOptions | buildConnector.connector; 64 | /** TODO */ 65 | maxRequestsPerClient?: number; 66 | /** TODO */ 67 | localAddress?: string; 68 | /** Max response body size in bytes, -1 is disabled */ 69 | maxResponseSize?: number; 70 | /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */ 71 | autoSelectFamily?: boolean; 72 | /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */ 73 | autoSelectFamilyAttemptTimeout?: number; 74 | /** 75 | * @description Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation. 76 | * @default false 77 | */ 78 | allowH2?: boolean; 79 | /** 80 | * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overriden by a SETTINGS remote frame. 81 | * @default 100 82 | */ 83 | maxConcurrentStreams?: number 84 | } 85 | export interface SocketInfo { 86 | localAddress?: string 87 | localPort?: number 88 | remoteAddress?: string 89 | remotePort?: number 90 | remoteFamily?: string 91 | timeout?: number 92 | bytesWritten?: number 93 | bytesRead?: number 94 | } 95 | } 96 | 97 | export default Client; 98 | --------------------------------------------------------------------------------