Skip to content

Commit 0fcdd45

Browse files
updated syntax
1 parent 250afa0 commit 0fcdd45

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

lesson_07/conditionals/src/part_a.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
* @return True if the age corresponds to a voting age and false otherwise.
66
*/
77
export function canVote(age: number): boolean {
8-
if (age >= 18) {
9-
return true;
10-
}
11-
else {
12-
return false;
13-
}
8+
return age >= 18;
149
}
1510
/**
1611
* Adds all of the provided values and returns the sum.
@@ -32,14 +27,5 @@ export function computeFactorial(n: number): number {
3227
if (n < 0) {
3328
throw new Error("Factorial is not defined for negative numbers.");
3429
}
35-
if (n === 0 || n === 1) {
36-
return 1;
37-
}
38-
39-
let result = 1;
40-
for (let i = 2; i <= n; i++) {
41-
result *= i;
42-
}
43-
44-
return result;
30+
return n <= 1 ? 1 : n * computeFactorial(n - 1);
4531
}

0 commit comments

Comments
 (0)