Created
September 4, 2015 02:13
-
-
Save suissa/258070ec1323783f83fa to your computer and use it in GitHub Desktop.
Examples of high order functions in JavaScript #01
This file contains hidden or 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
function somar(x, y) { | |
return x + y; | |
}; | |
function subtrair(x, y) { | |
return x - y; | |
}; | |
function multiplicar(x, y) { | |
return x * y; | |
}; | |
function dividir(x, y) { | |
return x / y; | |
}; | |
function calcular(op, x, y) { | |
return op(x, y); | |
}; | |
calcular(somar, 400, 20); // 420 | |
calcular(subtrair, 700, 34); // 666 | |
calcular(multiplicar, 333, 2); // 666 | |
calcular(dividir, 840, 2); // 420 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment