-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path03-code-refactoring.ts
More file actions
35 lines (34 loc) · 862 Bytes
/
03-code-refactoring.ts
File metadata and controls
35 lines (34 loc) · 862 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
// The code below is a simple function that compares three numbers
// and returns the sum of the positive ones.
function sumPositiveNumbers(a: number, b: number, c: number): number {
if (a > 0) {
if (b > 0) {
if (c > 0) {
return a + b + c;
} else {
return a + b;
}
} else {
if (c > 0) {
return a + c;
} else {
return a;
}
}
} else {
if (b > 0) {
if (c > 0) {
return b + c;
} else {
return b;
}
} else {
if (c > 0) {
return c;
} else {
return 0;
}
}
}
}
// Prompt in Ask: Refactor the code to make it more readable and effective.