Skip to content

Commit a1c42cb

Browse files
author
umbur
committed
completes factorial
1 parent 288713b commit a1c42cb

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

factorial.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Write a function that takes a positive integer and return its factorial.
2+
// Examples:
3+
// factorial(4) ➞ 24
4+
// factorial(0) ➞ 1
5+
// factorial(9) ➞ 362880
6+
// Notes:
7+
// The factorial of 0 is 1.
8+
// The factorial of any positive integer Z is Z * (Z - 1) * (Z - 2) * . . . . . . * 1 (e.g. factorial of 3 is 3 * 2 * 1 = 6).
9+
10+
function factorial(z) {
11+
let total = 1;
12+
if (z == 0) {
13+
return 1;
14+
} else {
15+
for (let i = 0; i < z; z--) {
16+
total *= z;
17+
}
18+
}
19+
return total;
20+
}
21+
console.log(factorial(4));
22+
console.log(factorial(0));
23+
console.log(factorial(9));

js_draft.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@
109109
// }
110110
// console.log(additiveInverse([5, -7, 8, 3]));
111111

112-
function repetition(txt, n) {
113-
return txt.repeat(n);
112+
// function repetition(txt, n) {
113+
// return txt.repeat(n);
114+
// }
115+
// console.log(repetition("ab", 3));
116+
117+
function filterArray(arr) {
118+
return arr.filter((n) => typeof n == "number");
114119
}
115-
console.log(repetition("ab", 3));
120+
console.log(filterArray([1, 2, "a", "b"]));

0 commit comments

Comments
 (0)