/*
greet('Привет')('Мир'); // 'Привет, Мир!'
greet('Hello')('John'); // 'Hello, John!'
*/
const greet = (a) => {
return (b) => {
return `${a}, ${b}`
}
}
const add = (a) => (b) => a + b;
const multiplyThree = (a) => (b) => (c) => a*b*c;
console.log(add(2)(3)); // 5
console.log(add(5)(7)); // 12
console.log(add(10)(-3)); // 7
console.log(multiplyThree(2)(3)(4)); // 24
multiplyThree(1)(5)(6); // 30
console.log(greet('Привет')('Мир')); // 'Привет, Мир!'
console.log(greet('Hello')('John')); // 'Hello, John!'
function sum(a, b, c) { return a + b + c; }
function curry(fn) {
return function curried(...args) {
if (args.length === fn.length) {
return fn(...args)
}
return function(...moreArgs) {
return
}
}
}
const curriedSum = curry(sum);
curriedSum(1)(2)(3); // 6
curriedSum(1, 2)(3); // 6
curriedSum(1)(2, 3); // 6
Click Run to execute JavaScript.
Code runs in an isolated environment.
Code runs in an isolated environment.