Created
January 2, 2016 21:47
-
-
Save pedroparra/d69de2c0e44e1fdf023a to your computer and use it in GitHub Desktop.
Funciones puras e impuras en javascript.
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
// Funcion Pura | |
function doble(num) { | |
return num * 2; // No modifica el argumento. | |
} | |
function doblarLista(listado){ | |
// Retorna un nuevo listado sin modificar nada. | |
return listado.map(doble); | |
} | |
// Funcion Impura | |
function doblarLista(listado){ | |
for( var i =0; i < listado.items; i++ ){ | |
// Cambiamos los valores entregados como argumentos | |
listado[i] = doble(listado[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment