We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 250afa0 commit 0fcdd45Copy full SHA for 0fcdd45
lesson_07/conditionals/src/part_a.ts
@@ -5,12 +5,7 @@
5
* @return True if the age corresponds to a voting age and false otherwise.
6
*/
7
export function canVote(age: number): boolean {
8
- if (age >= 18) {
9
- return true;
10
- }
11
- else {
12
- return false;
13
-}
+ return age >= 18;
14
}
15
/**
16
* Adds all of the provided values and returns the sum.
@@ -32,14 +27,5 @@ export function computeFactorial(n: number): number {
32
27
if (n < 0) {
33
28
throw new Error("Factorial is not defined for negative numbers.");
34
29
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);
45
31
0 commit comments