Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript-Challenges-Ivy-Saskia-Sejas-Rocabado #185

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ npm run test
15 = 1 307 674 368 000.
```

1. Genera un algoritmo para determinar si un número de entrada es primo o no.
2. Genera una función que devuelve una secuencia de Fibonacci como una array
2. Genera un algoritmo para determinar si un número de entrada es primo o no.

3. Genera una función que devuelve una secuencia de Fibonacci como una array

### Enviar solución de reto

Expand Down
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/factorial.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const factorial = (number) => {
// your code here
if (number == 0 || number == 1) return 1;
return number * factorial (number-1);
}

module.exports = factorial;
7 changes: 6 additions & 1 deletion src/fibonacci.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const fibonacci = (n) => {
// your code here
if (n == 0) return [0];
if (n == 1) return [1];
if (n == 2) return [1, 1];
let fibonacciArray = fibonacci(n - 1);
fibonacciArray.push(fibonacciArray[n - 2] + fibonacciArray[n - 3]);
return fibonacciArray;
}

module.exports = fibonacci;
7 changes: 5 additions & 2 deletions src/primalidad.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const trialDivision = (number) => {
// your code here
const trialDivision = (number) => {
if (number % 1 !== 0) return false;
for (let i = 2; i < number; i++)
if (number % i === 0) return false;
return number >= 2;
}

module.exports = trialDivision;