LeetCode 2667. Create Hello World Function TypeScript Solution | Explanation + Code

CoderIndeed
0
2667. Create Hello World Function

Description

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

Solutions

Solution 1

TypeScript
function createHelloWorld() { return function (...args): string { return 'Hello World'; }; } /** * const f = createHelloWorld(); * f(); // "Hello World" */(code-box)

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !