DEV Community

_Khojiakbar_
_Khojiakbar_

Posted on • Edited on

1

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more