Created
June 23, 2017 05:03
-
-
Save byron-perez/345fd78c4881e7160950dcc2f85db97c to your computer and use it in GitHub Desktop.
version recursiva de algoritmos
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
<script> | |
function factorialRecursivo(n){ | |
var x = parseInt(n); | |
if(x == 0) return 1; | |
return x * factorialRecursivo(x - 1); | |
} | |
function sumarElemsArrayRecursivo(arr) | |
{ | |
if (arr.length == 0) return 0; | |
return arr[0] + sumarElemsArrayRecursivo(arr.slice(1)); | |
} | |
function multiplicarElemsArrayRecursivo(arr) | |
{ | |
if (arr.length == 0) return 1; | |
return arr[0] * multiplicarElemsArrayRecursivo(arr.slice(1)); | |
} | |
function findMinRecursivo(arr, smallest){ | |
if (arr.length === 0){ | |
return smallest; | |
} | |
else { | |
var first = arr.shift(); | |
if (first < smallest || smallest === undefined){ | |
smallest = first; | |
} | |
return recur(arr, smallest); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment