Last active
June 29, 2022 07:20
-
-
Save hoangbits/da7c3cf02b4a3c1502e848d1edfa50b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *********** START DE QUY ************** | |
// | |
// tuong tuong co nhieu ham add | |
// | |
// function add(number){ | |
// if(number <= 0) { | |
// return 0; | |
// } | |
// return number + add(number - 1) | |
// } | |
function add(number){ | |
if(number <= 0) { | |
return 0; | |
} | |
return number + add(number - 1) | |
} | |
// | |
// *********** END DE QUY ************** | |
// *********** START MINH HOA DE QUY ************** | |
function add0(number){ | |
if(number <= 0) { | |
return 0; | |
} | |
return number + add0(number - 1) | |
} | |
function add1(number){ | |
if(number <= 0) { | |
return 0; | |
} | |
return number + add0(number - 1) | |
} | |
function add2(number){ | |
if(number <= 0) { | |
return 0; | |
} | |
return number + add1(number - 1) | |
} | |
// *********** KET THUC MINH HOA DE QUY ************** | |
console.log("add0(0):", add0(0)) // 0 | |
console.log("add1(1):", add1(1)) // 1 | |
console.log("add2(2):", add2(2)) // 3 | |
console.log("add(1):", add(1)) // 1 | |
console.log("add(0):", add(0)) // 0 | |
console.log("add(2):", add(2)) // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment