Currying function🤓

__khojiakbar__

_Khojiakbar_

Posted on June 13, 2024

Currying function🤓

Funny Samples:

// 1. Phrase

function gap(a) {
    return function(b) {
        return function(c) {
            return `${a[0].toUpperCase()}${a.slice(1)} ${b} ${c}`;
        }
    }
}
res = add('Hello')(['World'])('?');

console.log(res);  // Hello World ?
Enter fullscreen mode Exit fullscreen mode

// 2. Compliment generator

function makeCompliment(name) {
    return function (adjective) {
        return function (activity) {
            return `${name}, you are so ${adjective} at ${activity} !`
        }
    }
}
let result = makeCompliment('Khojiakbar')('bad')('coding')

console.log(result);  // Khojiakbar, you are so bad at coding !
Enter fullscreen mode Exit fullscreen mode

// 3. Silly Story Maker

function makeStory(name) {
    return function (noun){
        return function (adverb) {
            return `${name}, was looking at ${noun}, ${adverb}. But the ${noun} wasn't made ${adverb}.`
        }
    }
}
result = makeStory('John')('bread')('happily')

console.log(result);  // John, was looking at bread, happily. But the bread wasn't made happily.
Enter fullscreen mode Exit fullscreen mode

// 4. Make food

function makeFood(ingredient_one) {
    return function(ingredient_two) {
        return function(cooking_style){
            return `Take ${ingredient_one} and ${ingredient_two} and mix them together with your hands and ${cooking_style} them.`
        }
    }
}
result = makeFood('cheese')('milk')('bake')

console.log(result);  // Take cheese and milk and mix them together with your hands and bake them.
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
__khojiakbar__
_Khojiakbar_

Posted on June 13, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related