Create Hello World Function

Write a function createHelloWorld. It should return a new function that always returns "Hello World".

Example 1:

Input: args = []
Output: "Hello World"
Explanation:
const f = createHelloWorld();
f(); // "Hello World"

The function returned by createHelloWorld should always return "Hello World".

Example 2:

Input: args = [{},null,42]
Output: "Hello World"
Explanation:
const f = createHelloWorld();
f({}, null, 42); // "Hello World"

Any arguments could be passed to the function but it should still always return "Hello World".

Constraints:

  • 0 <= args.length <= 10

Hey Wait wait wait ---> Before checking the solution below can you try with yourself first by following the URL and trying with yourself on leetcode.

https://leetcode.com/problems/create-hello-world-function/?envType=study-plan-v2&envId=30-days-of-javascript

Here is the Solution

/**
 * @return {Function}
 */
var createHelloWorld = function() {

    return function(...args) {
     return "Hello World";
    }
};


/**
 * const f = createHelloWorld();
 * f(); // "Hello World"
 */

Thank You

0
Subscribe to my newsletter

Read articles from Abhishek Dandriyal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhishek Dandriyal
Abhishek Dandriyal

Frontend Developer , I design and code user-friendly and responsive web applications and projects using,HTML5 , React /Redux MUI . I collaborate with backend developer, UI/UX designers, and project managers to deliver high-quality products that meet the clients' needs and expectations.