math_example_mh
Version:
Un example de création de package
64 lines (57 loc) • 1.15 kB
JavaScript
var call_counter = require('./call_counter');
function multiple(x,y){
call_counter();
return x*y;
}
function divide(x,y){
call_counter();
if (y!=0)
return x/y;
else
return 0;
}
// My fibo function
function fibonacci (n){
/*var result_tab[];
result_tab[0]=0;
result_tab[1]=1;*/
if(n < 0)
return 0;
else {
var count1 = 0;
var result = 1;
var temp = 0;
for (i = 1; i < n; i++){
temp = count1;
count1 = result;
result = result + temp;
//result_tab[i] = result;
}
return result;
//return result_tab;
}
}
// Prof fibo functions
function fibo(count){
call_counter();
return private_fibo();
}
function private_fibo(count, counter, first, second){
if(count == 0) return 0;
if (count == undefined){
counter = 1;
first = 1;
second = 2;
}
result = first+second;
if (counter == count) return result;
private_fibo(count, ++counter, second, result);
return result;
}
// export des fonctions
module.exports = {
multiplier : multiple,
diviser : divide,
fibonacci,
fibo
}