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 to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay