Skip to content

Instantly share code, notes, and snippets.

@jamc92
Created February 22, 2015 16:18
Show Gist options
  • Save jamc92/4b3885da23ae0cfdda0c to your computer and use it in GitHub Desktop.
Save jamc92/4b3885da23ae0cfdda0c to your computer and use it in GitHub Desktop.
JS - Function as a Parameter
<!--(method - filter())-->
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Function as a Parameter - Lambdas</title>
<script src="main.js"></script>
</head>
<body>
</body>
</html>
// Si no existe la variable, crear el arreglo
if (!NSLambdas) {
var NSLambdas = {};
}
//Se le asigna a la variable creada el metodo filtro, para filtrar segun la regla de la funcion
NSLambdas.filter = function() {
//Se asigna el arreglo y sus elementos
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
//Se asigna resultado de la funcion del filtro para que retorne el modulus del elemento por 2
var odd = numbers.filter(function(element) {
return element % 2;
});
//Imprime el contenido de la variable odd
console.log(odd);
};
//Se crea la funcion para que al momento de cargar la pagina, la ventana llame al evento al cargar
//la funcion que hace el llamado al filtro de la variable NSLambdas
(function() {
window.addEventListener("load", function() {
NSLambdas.filter();
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment