Function composition on data pipelines and error handling.
//The arguments values are cached in the returned function
function translate2d(dx, dy) {
return function (x, y){
return [dx + x, dy + y]
}
}
const move2x = translate2d(2, 0); //move2x() is the returned function
const result = move2x(4, 8); //result is the returned operation result
console.log( result ) //[6, 8]//Local variables can be set and used down the line
//Passed functions can be used with later invoked arguments
function memoize(f) {
let preX, preY, preR
return function (x, y) {
if (preX === x && preY === y) {
console.log("already casted")
return preR
}
preX = x
preY = y
return preR = f(x, y)
}
}Functions execution order on reduce() function compositions.
Function composition on Error Handling
PreviousJS 1: variables, functions, parameters, array methods, data types, Math operations and HTML implementationNextJS 2, String array methods, If and Switch statements, let and var properties, HTML forms and js validation and setInterval()/setTimeout()
Last updated