26 lines
558 B
JavaScript
26 lines
558 B
JavaScript
|
const assert = require("assert")
|
||
|
|
||
|
const fibonacci_rec = function(n) {
|
||
|
assert.ok(Number.isInteger(n), "n is not an Integer!")
|
||
|
if(n == 0) {
|
||
|
return 0
|
||
|
} else if (n == 1) {
|
||
|
return 1
|
||
|
} else {
|
||
|
return fibonacci_rec(n - 1) + fibonacci_rec(n - 2)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const fibonacci_opt = function(n) {
|
||
|
const g = function(n) {
|
||
|
return (1 + Math.sqrt(5)) / 2
|
||
|
}
|
||
|
assert.ok(Number.isInteger(n), "n is not an Integer!")
|
||
|
if(n == 0) {
|
||
|
return 0
|
||
|
} else if (n == 1) {
|
||
|
return 1
|
||
|
} else {
|
||
|
|
||
|
}
|
||
|
}
|