Skip to content

Instantly share code, notes, and snippets.

@0GiS0
Created Jun 23, 2019
Embed
What would you like to do?
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