-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecture-4.js
More file actions
40 lines (28 loc) · 859 Bytes
/
lecture-4.js
File metadata and controls
40 lines (28 loc) · 859 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
function calculateFactorial(num) {
if (typeof num !== 'number' || num < 0) {
return 'Enter non-zero number only';
}
let result = 1;
for (let i = 1; i <= num; i++) {
result *= i;
}
return `${result}!`;
}
// 4*3*2*1 = 24!
console.log(calculateFactorial(4));
// Given an integer n, find its factorial. Return a list of integers denoting the digits that make up the factorial of n.
// Examples:
// Input: n = 10
// Output: [3, 6, 2, 8, 8, 0, 0]
// Explanation: 10! = 1*2*3*4*5*6*7*8*9*10 = 3628800
function findFactorial(numInput) {
if (typeof numInput !== 'number' || numInput < 0) {
return `Enter valid non-zero number only`
}
let result = [];
for (let i = 1; i <= numInput; i++) {
result.push(i);
}
return result;
}
console.log(findFactorial(10));