This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateFibonacci(number) { | |
if (number == 0 || number == 1) | |
return number; | |
return (calculateFibonacci(number - 1) + calculateFibonacci(number - 2)); | |
} | |
function doStuff(serie) { | |
return new Promise((resolve, reject) => { | |
if (typeof serie === 'number') { | |
var results = []; | |
for (var i = 0; i > serie - 1; i++) { | |
var result = calculateFibonacci(i); | |
console.log(result); | |
results.push(result); | |
} | |
console.log("for finished"); | |
resolve(results.join(", ")); | |
} else { | |
reject(new Error('Argument serie must be a number')); | |
} | |
}) | |
} | |
doStuff(10) | |
.then(result => console.log(`Result: ${result}`)) | |
.catch(error => console.log(`Something bad happened: ${error}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment