mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
573 B
19 lines
573 B
/** |
|
* Calculate a fibonacci number by calling callbacks with intermediate results, |
|
* switching between Rust and JavaScript. |
|
* @param {number} a The fibonacci number to calculate. |
|
* @param {function} callback_a A callback method. |
|
* @param {function} callback_b A callback method. |
|
* @returns {number} The {a}th fibonacci number. |
|
*/ |
|
export function fibonacci(a, callback_a, callback_b) { |
|
if (a <= 1) { |
|
return a; |
|
} |
|
|
|
// Switch the callbacks around. |
|
return ( |
|
callback_a(a - 1, callback_b, callback_a) + |
|
callback_b(a - 2, callback_b, callback_a) |
|
); |
|
}
|
|
|