Skip to content

Commit cbef0ea

Browse files
committed
add new files
1 parent 259107b commit cbef0ea

14 files changed

+482
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Class-10/fun.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Basic Syntax
2+
// function functionName(param1, param2) {
3+
// function body
4+
//}
5+
var myFriends = ['aisha', 'areesha'];
6+
var unFriends = [];
7+
// function declaration with parameters
8+
function addFriend(name) {
9+
// function body
10+
// Push name to array
11+
myFriends.push(name);
12+
}
13+
addFriend('usman');
14+
addFriend('sunny');
15+
console.log("--------------------------------------------");
16+
// Function with return type
17+
function removeFriend(name) {
18+
// Remove name from array
19+
var myNewFriends = [];
20+
for (var _i = 0, myFriends_1 = myFriends; _i < myFriends_1.length; _i++) {
21+
var friend = myFriends_1[_i];
22+
if (friend !== name) {
23+
myNewFriends.push(friend);
24+
}
25+
myFriends = myNewFriends;
26+
}
27+
return name;
28+
}
29+
var removedFriend = removeFriend('areesha');
30+
unFriends.push(removedFriend);
31+
console.log('myFriends', myFriends);
32+
console.log('unFriends', unFriends);

Class-10/fun.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Basic Syntax
2+
// function functionName(param1, param2) {
3+
// function body
4+
//}
5+
6+
let myFriends: string[] = ['aisha','areesha'];
7+
const unFriends: string[] = [];
8+
9+
// function declaration with parameters
10+
function addFriend(name: string): void {
11+
12+
// function body
13+
// Push name to array
14+
myFriends.push(name);
15+
16+
}
17+
18+
addFriend('usman');
19+
addFriend('sunny');
20+
21+
console.log("--------------------------------------------");
22+
23+
24+
// Function with return type
25+
function removeFriend(name: string): string {
26+
27+
// Remove name from array
28+
let myNewFriends: string[] = [];
29+
30+
for (const friend of myFriends) {
31+
if (friend !== name) {
32+
myNewFriends.push(friend);
33+
}
34+
myFriends = myNewFriends;
35+
}
36+
return name;
37+
}
38+
39+
const removedFriend = removeFriend('areesha');
40+
unFriends.push(removedFriend);
41+
42+
console.log('myFriends', myFriends);
43+
console.log('unFriends', unFriends);

Class-10/function.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
function myInfo() {
2+
// function body
3+
console.log("Hi my name is Isfhan Ahmed");
4+
console.log("I am from Pakistan");
5+
console.log("I am a Software engineer");
6+
console.log("-----------------------------");
7+
}
8+
myInfo(); // invoke function
9+
myInfo();
10+
myInfo();
11+
myInfo();
12+
// Function with required parameters
13+
function myInfoWithParameter(name, country, job) {
14+
// function body
15+
console.log("Hi my name is", name); // Argument pass log
16+
console.log("I am from ".concat(country)); // template string
17+
console.log("I am a " + job); // concatenation
18+
console.log("-----------------------------");
19+
}
20+
myInfoWithParameter("Aisha", "Pakistan", "Teacher");
21+
myInfoWithParameter("Areesha", "Pakistan", "Teacher and Programmer");
22+
myInfoWithParameter("Muneeb", "Pakistan", "Programmer");
23+
myInfoWithParameter("Sunny", "Pakistan", "Typescript Programmer");
24+
// Function with Default Parameters
25+
function myInfoWithDefaultParameter(name, country, job) {
26+
if (job === void 0) { job = "Software Engineer"; }
27+
// function body
28+
console.log("Hi my name is", name); // Argument pass log
29+
console.log("I am from ".concat(country)); // template string
30+
console.log("I am a " + job); // concatenation
31+
console.log("-----------------------------");
32+
}
33+
myInfoWithDefaultParameter("zubaida", "Pakistan");
34+
myInfoWithDefaultParameter("usman", "Pakistan");
35+
myInfoWithDefaultParameter("Aisha", "Pakistan", "Teacher");
36+
// Function with Optional Parameters
37+
function myInfoWithOptionalParameter(name, country, job) {
38+
// function body
39+
console.log("Hi my name is", name); // Argument pass log
40+
console.log("I am from ".concat(country)); // template string
41+
if (job) {
42+
console.log("I am a " + job); // concatenation
43+
}
44+
console.log("-----------------------------");
45+
}
46+
myInfoWithOptionalParameter("Noor ul huda", "Pakistan");
47+
// Function with Return Type
48+
function myFunctionWithReturnType(n1, n2) {
49+
// return n1 + n2;
50+
return n1 + n2;
51+
}
52+
var result = myFunctionWithReturnType(10, 20);
53+
console.log(result);
54+
console.log(myFunctionWithReturnType(50, 20));
55+
// Function that hoisted
56+
logDate();
57+
function logDate() {
58+
var date = new Date();
59+
console.log(date);
60+
}
61+
// function expression
62+
var myInfoWithFunctionExpression = function () {
63+
// function body
64+
console.log("Hi my name is Isfhan Ahmed");
65+
console.log("I am from Pakistan");
66+
};
67+
myInfoWithFunctionExpression();
68+
// Self Invoking Function
69+
(function () {
70+
// function body
71+
console.log("Hi I am Isfhan from self invoking function");
72+
})();
73+
// Arrow Function
74+
var myMultiplicationWithArrowFunction = function (num1, num2) { return num1 * num2; };
75+
var result2 = myMultiplicationWithArrowFunction(10, 20);
76+
console.log(result2);
77+
// Before Arrow Function expression
78+
var beforeArrowFunction = function (num1, num2) {
79+
return num1 - num2;
80+
};
81+
console.log(beforeArrowFunction(123, 23));
82+
// Arrow Function with Rest Parameters
83+
var sumAllNumbers = function (message) {
84+
var numbers = [];
85+
for (var _i = 1; _i < arguments.length; _i++) {
86+
numbers[_i - 1] = arguments[_i];
87+
}
88+
console.log(numbers);
89+
console.log(typeof numbers);
90+
console.log(message);
91+
var total = 0;
92+
for (var _a = 0, numbers_1 = numbers; _a < numbers_1.length; _a++) {
93+
var number = numbers_1[_a];
94+
total += number; // total = total + number
95+
}
96+
return total;
97+
};
98+
var result3 = sumAllNumbers("hello i am rest parameters function", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
99+
console.log(result3);

Class-10/function.ts

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
function myInfo(): void { // function declaration
2+
3+
// function body
4+
console.log("Hi my name is Isfhan Ahmed");
5+
console.log("I am from Pakistan");
6+
console.log("I am a Software engineer");
7+
8+
console.log("-----------------------------");
9+
10+
}
11+
12+
13+
myInfo(); // invoke function
14+
myInfo();
15+
myInfo();
16+
myInfo();
17+
18+
19+
// Function with required parameters
20+
function myInfoWithParameter(name: string, country: string, job: string): void {
21+
22+
// function body
23+
console.log("Hi my name is", name); // Argument pass log
24+
console.log(`I am from ${country}`); // template string
25+
console.log("I am a " + job); // concatenation
26+
27+
console.log("-----------------------------");
28+
}
29+
30+
31+
myInfoWithParameter("Aisha", "Pakistan", "Teacher");
32+
myInfoWithParameter("Areesha", "Pakistan", "Teacher and Programmer");
33+
myInfoWithParameter("Muneeb", "Pakistan", "Programmer");
34+
myInfoWithParameter("Sunny", "Pakistan", "Typescript Programmer");
35+
36+
37+
38+
// Function with Default Parameters
39+
function myInfoWithDefaultParameter(name: string, country: string, job: string = "Software Engineer"): void {
40+
41+
// function body
42+
console.log("Hi my name is", name); // Argument pass log
43+
console.log(`I am from ${country}`); // template string
44+
console.log("I am a " + job); // concatenation
45+
46+
console.log("-----------------------------");
47+
48+
}
49+
50+
51+
myInfoWithDefaultParameter("zubaida", "Pakistan");
52+
myInfoWithDefaultParameter("usman", "Pakistan");
53+
myInfoWithDefaultParameter("Aisha", "Pakistan", "Teacher");
54+
55+
56+
// Function with Optional Parameters
57+
function myInfoWithOptionalParameter(name: string, country: string, job?: string): void {
58+
59+
// function body
60+
console.log("Hi my name is", name); // Argument pass log
61+
console.log(`I am from ${country}`); // template string
62+
63+
if (job) {
64+
65+
console.log("I am a " + job); // concatenation
66+
}
67+
68+
console.log("-----------------------------");
69+
}
70+
71+
myInfoWithOptionalParameter("Noor ul huda", "Pakistan");
72+
73+
74+
75+
// Function with Return Type
76+
function myFunctionWithReturnType(n1: number, n2: number): number {
77+
78+
// return n1 + n2;
79+
80+
return n1 + n2;
81+
}
82+
83+
const result: number = myFunctionWithReturnType(10, 20);
84+
console.log(result);
85+
console.log(myFunctionWithReturnType(50, 20));
86+
87+
// Function that hoisted
88+
logDate();
89+
90+
function logDate(): void {
91+
92+
const date: Date = new Date();
93+
console.log(date);
94+
}
95+
96+
// function expression
97+
const myInfoWithFunctionExpression = function (): void {
98+
99+
// function body
100+
console.log("Hi my name is Isfhan Ahmed");
101+
console.log("I am from Pakistan");
102+
103+
}
104+
105+
myInfoWithFunctionExpression();
106+
107+
108+
// Self Invoking Function
109+
(function () {
110+
111+
// function body
112+
console.log("Hi I am Isfhan from self invoking function");
113+
114+
})();
115+
116+
117+
// Arrow Function
118+
const myMultiplicationWithArrowFunction = (num1: number, num2: number) => num1 * num2;
119+
120+
const result2: number = myMultiplicationWithArrowFunction(10, 20);
121+
console.log(result2);
122+
123+
// Before Arrow Function expression
124+
const beforeArrowFunction = function (num1: number, num2: number): number {
125+
126+
return num1 - num2;
127+
128+
};
129+
130+
console.log(beforeArrowFunction(123, 23));
131+
132+
// Arrow Function with Rest Parameters
133+
const sumAllNumbers = (message: string, ...numbers: number[]): number | void => {
134+
console.log(numbers);
135+
console.log(typeof numbers);
136+
137+
console.log(message);
138+
139+
let total: number = 0;
140+
for (const number of numbers) {
141+
total += number; // total = total + number
142+
}
143+
144+
return total;
145+
}
146+
147+
const result3: number | void = sumAllNumbers("hello i am rest parameters function", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
148+
console.log(result3);

Class-7/tuples.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
"use strict";
12
// create tuple
2-
var ourTuple = [5, false, 'Coding was here'];
3+
let ourTuple = [5, false, 'Coding was here'];
34
// We have no type safety in our tuple for indexes 3+
45
ourTuple.push('Something new and wrong');
56
ourTuple.push(100);

Class-8/for-loop.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
// basic syntax of for loop
23
// for (initialization; condition; increment/decrement) {
34
// statement
@@ -6,25 +7,25 @@
67
// Condition is used to check if the loop should continue
78
// Increment/decrement is used to update the value of i
89
// simple for loop that will print 0 to 100 numbers
9-
for (var i = 0; i < 100; i++) {
10+
for (let i = 0; i < 100; i++) {
1011
console.log(i);
1112
}
1213
console.log("-----------------");
1314
// simple for loop that will print I will not late in class anymore 100 times
14-
for (var i = 0; i < 100; i++) {
15+
for (let i = 0; i < 100; i++) {
1516
console.log("I will not late in class anymore");
1617
}
1718
console.log("-----------------");
1819
// for loop that will print table of 5
19-
for (var i = 1; i <= 10; i++) {
20-
var tableNumber = 5;
20+
for (let i = 1; i <= 10; i++) {
21+
let tableNumber = 5;
2122
console.log(tableNumber, "x", i, "=", tableNumber * i); // 5x1=5, ... 5x10=50
2223
}
2324
// Array is used to store multiple values in a single variable
24-
var cars = ["BMW", "Volvo", "Saab", "Ford"];
25-
var dataLength = cars.length;
25+
const cars = ["BMW", "Volvo", "Saab", "Ford"];
26+
let dataLength = cars.length;
2627
// Using for loop to iterate over an array and print the value of each element
27-
for (var i = 0; i < dataLength; i++) {
28+
for (let i = 0; i < dataLength; i++) {
2829
console.log("dataLength", dataLength);
2930
console.log("My car is", cars[i]);
3031
}

Class-8/for-of.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
"use strict";
12
// Basic syntax of for of loop
23
// for (variable of iterable) {
34
// statement
45
// }
56
// Array is used to store multiple values in a single variable
6-
var girls = ["sana", "sara", "ayesha", "marry"];
7-
var index = 1;
7+
const girls = ["sana", "sara", "ayesha", "marry"];
8+
let index = 1;
89
// for of loop is used to iterate over an iterable object (like an array or a string)
9-
for (var _i = 0, girls_1 = girls; _i < girls_1.length; _i++) {
10-
var girl = girls_1[_i];
11-
console.log("my ".concat(index, " sister is ").concat(girl));
10+
for (let girl of girls) {
11+
console.log(`my ${index} sister is ${girl}`);
1212
index++;
1313
}

0 commit comments

Comments
 (0)