freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../basic-algorithm-scripting/factorialize-a-number.spani...

77 lines
2.0 KiB
Markdown
Raw Normal View History

2018-10-08 17:34:43 +00:00
---
id: a302f7aae1aa3152a5b413bc
title: Factorialize a Number
localeTitle: Factorializar un número
isRequired: true
challengeType: 5
---
## Description
<section id='description'>
Devuelve el factorial del entero proporcionado.
Si el entero se representa con la letra n, un factorial es el producto de todos los enteros positivos menores o iguales a n.
factoriales a menudo se representan con la notación abreviada <code>n!</code>
Por ejemplo: <code>5! = 1 * 2 * 3 * 4 * 5 = 120</code>
Solo se proporcionarán a la función números enteros mayores o iguales a cero.
Recuerda usar <a href="http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514" target="_blank">Read-Search-Ask</a> si te atascas. Escribe tu propio código.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>factorialize(5)</code> debe devolver un número.
testString: 'assert(typeof factorialize(5) === "number", "<code>factorialize(5)</code> should return a number.");'
- text: <code>factorialize(5)</code> debe devolver 120.
testString: 'assert(factorialize(5) === 120, "<code>factorialize(5)</code> should return 120.");'
- text: <code>factorialize(10)</code> debe devolver 3628800.
testString: 'assert(factorialize(10) === 3628800, "<code>factorialize(10)</code> should return 3628800.");'
- text: <code>factorialize(20)</code> debe devolver 2432902008176640000.
testString: 'assert(factorialize(20) === 2432902008176640000, "<code>factorialize(20)</code> should return 2432902008176640000.");'
- text: <code>factorialize(0)</code> debe devolver 1.
testString: 'assert(factorialize(0) === 1, "<code>factorialize(0)</code> should return 1.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function factorialize(num) {
return num;
}
factorialize(5);
```
</div>
</section>
## Solution
<section id='solution'>
```js
function factorialize(num) {
return num < 1 ? 1 : num * factorialize(num - 1);
}
factorialize(5);
```
</section>