matematicabisao83
Version:
Um exemplo de projeto node com operações matemáticas
42 lines (35 loc) • 1.21 kB
JavaScript
var call_counter = require('./contadorDeChamadas');
function multiply(x, y){
call_counter();
return x * y;
}
function divide(x, y){
call_counter();
return x / y;
}
function fibo(count) {
call_counter();
return private_fibo(count)
}
// The fibo function calls the private_fibo function, a recursive function that calls itself until
// the count and counter are equal. The private_fibo function is not exported, so it will be accessible
// only from the fibo function that is exported.
function private_fibo(count, counter, first, second) {
if (count == 0) return 0;
if (counter == undefined) {
counter = 1
first = 1;
second = 2;
}
result = first + second;
if (counter == count)
return result;
private_fibo(count, ++counter, second, result)
return result;
}
//The advanced_math.js module exports three functions, so an object is created to provide access to these functions.
module.exports = {
multiplication: multiply,
division: divide,
fibonacci : fibo
}