forked from Zelechos/Pragmatic_JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise26.js
More file actions
25 lines (23 loc) · 965 Bytes
/
Copy pathExercise26.js
File metadata and controls
25 lines (23 loc) · 965 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) Programa una función que calcule el factorial de un número (El factorial de un entero positivo n, se define como el producto de todos los números enteros positivos desde 1 hasta n), pe. miFuncion(5) devolverá 120.
import factorial from './factorial.js';
import { validateNumber } from './validations.js';
'use strict'
const calculateFactorial = number =>
(validateNumber(number))
? (number >= 0)
?console.log(`the factorial of ${number} \n is => ${factorial(number)}`)
:console.error(`negative numbers are not accepted!!!`)
: console.warn(`wrong parameter => parameter{${typeof(number)}} \n was expected => parameter{number}`);
// Testing
calculateFactorial(9);
calculateFactorial(8);
calculateFactorial(0);
calculateFactorial(1);
calculateFactorial(5);
calculateFactorial([]);
calculateFactorial({});
calculateFactorial();
calculateFactorial(true);
calculateFactorial("80");
calculateFactorial(-5);
calculateFactorial(-50);