Instagram | Twitter | LinkedIn
How should I run the following function to get the number 24 as a result of the multiplication: A, B or C?
Click here to see the correct answer and explanation 馃憖
Correct Answer | Explanation |
---|---|
B | Currying is a process in functional programming in which we can transform a function with multiple arguments (function mul(a, b, c) { return a * b * c } ) into a sequence of nesting functions (like the example of this quiz). It returns a new function that expects the next argument inline. To get the result of multiplication of the three numbers 2, 3 and 4, the numbers are passed one after the other, each number prefilling the next function inline for invocation. |
Explanation based on 馃憠馃徏 Understanding Currying in JavaScript
Code:
function mul(x) {
return function(y) {
return function(z) {
return x * y * z;
};
};
}
驴C贸mo deber铆a ejecutar la siguiente funci贸n para obtener el n煤mero 24 como resultado de la multiplicaci贸n: A, B o C?
Haz click aqu铆 para ver la respuesta correcta y su explicaci贸n 馃憖
Respuesta correcta | Explicaci贸n |
---|---|
B | Currying es un proceso de programaci贸n funcional en el que podemos transformar una funci贸n con m煤ltiples argumentos (function mul(a, b, c) { return a * b * c } ) en una secuencia de funciones anidadas (como el ejemplo de este qu铆z). Este proceso devuelve una nueva funci贸n que espera el siguiente argumento en l铆nea. Para obtener el resultado de la multiplicaci贸n de los tres n煤meros 2, 3 y 4, los n煤meros se pasan uno tras otro, cada n煤mero es pasado previamente a la siguiente funci贸n en l铆nea para su invocaci贸n. |
Explicaci贸n basada en 馃憠馃徏 Understanding Currying in JavaScript
C贸digo:
function mul(x) {
return function(y) {
return function(z) {
return x * y * z;
};
};
}
Wow