forked from mubashirimtiaz/concurrency-javascript-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.ts
More file actions
45 lines (37 loc) · 743 Bytes
/
function.ts
File metadata and controls
45 lines (37 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//EXPECT NUMBER
function add(a: number, b: number): number {
return a + b;
}
//EXPECT STRING
function greet(name: string): string {
return `Hello ${name}`;
}
//EXPECT BOOLEAN
function powerOutage(light: boolean): void {
if (light) {
console.log('There is light');
} else {
console.log('Power outage');
}
}
//EXPECT ARRAY
function customFind(arr: string[], element: string): boolean | void {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === element) {
return true;
}
}
}
//EXPECT OBJECT
function logPersonName(person: TPerson): void {
console.log(person.name);
}
type TPerson = {
name: string;
age: number;
};
const person: TPerson = {
name: 'John',
age: 30,
};
logPersonName(person);