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

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series