Skip to content

Instantly share code, notes, and snippets.

@0GiS0
Created June 23, 2019 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0GiS0/2e0a2a1a8e7ecfd1d791addc1f866483 to your computer and use it in GitHub Desktop.
Save 0GiS0/2e0a2a1a8e7ecfd1d791addc1f866483 to your computer and use it in GitHub Desktop.
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