Skip to content

Instantly share code, notes, and snippets.

@shcyiza
Last active February 28, 2020 09:52
Show Gist options
  • Save shcyiza/eb5e2cdcfad27b5fd5d71d2fe2c3c0ac to your computer and use it in GitHub Desktop.
Save shcyiza/eb5e2cdcfad27b5fd5d71d2fe2c3c0ac to your computer and use it in GitHub Desktop.
tail recurssion
// some jusque
// Method de accumulateur
function som_till(n,A=0){
if(n<0){
return A;
}
return som_till(n-1,n+A)
}
console.log(`som from all int from 0 till 6 is ${som_till(6)}`)
// fubonacci
// Method de DEUX accumulateurs!!!! trop fort poto!!!!
function fub(n, A0=0, A1=1){
if(n<=0){
return 0;
}
if(n<=1){
return A1;
}
return fub(n-1, A1, A0+A1)
}
console.log(`14th fubonacci number is ${fub(14)}`)
@jiraguha
Copy link

Well done Bro. Une petite amelioration:

function fub(n, A0=0, A1=1){
    if(n<=0){
        return A1;
    }
    return fub(n-1, A1, A0+A1)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment