Talentd
FleetCode

2667. Create Hello World Function

Easy81.6% acceptance9 companies
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
14:04
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1/**
2 * @return {Function}
3 */
4var createHelloWorld = function() {
5
6 return function(...args) {
7
8 }
9};
10
11/**
12 * const f = createHelloWorld();
13 * f(); // "Hello World"
14 */
Starter codeJavaScriptSpaces: 4
Examples
Input
[]
Input
[{},null,42]
Your code is saved on this device.Solution