diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..fc5c093 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,10 @@ const factorial = (number) => { - // your code here + let result = 1 + while(number){ + result *= number + number-=1 + } + return result } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..14fd6d2 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,12 @@ const fibonacci = (n) => { - // your code here + let memo = [0,1] + while(n>1){ + const nextFibo = memo[memo.length-1] + memo[memo.length-2] + memo.push(nextFibo) + n -= 1 + } + memo.shift() + return memo } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..d566b8b 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,22 @@ const trialDivision = (number) => { - // your code here + // validation of decimals + if(number != parseInt(number)) return false + // validation negativos + if(number <= 1) return false + // if it is 2 is correct + if(number == 2) return true + + let min = 2; + let max = number; + + while(min < max){ + if(number % min==0){ + return false; + } + max = parseInt(number/min)+1; + min += 1; + } + return true; } module.exports = trialDivision; \ No newline at end of file