Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f5ee536

Browse files
LeetCode First solution added
1 parent 46526a4 commit f5ee536

File tree

1 file changed

+48
-0
lines changed
  • LeetCode/30daysJavaScript/1.Create-Hello-World-Function

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
3+
4+
Write a function createHelloWorld. It should return a new function that always returns "Hello World".
5+
6+
7+
Example 1:
8+
9+
Input: args = []
10+
Output: "Hello World"
11+
Explanation:
12+
const f = createHelloWorld();
13+
f(); // "Hello World"
14+
15+
The function returned by createHelloWorld should always return "Hello World".
16+
Example 2:
17+
18+
Input: args = [{},null,42]
19+
Output: "Hello World"
20+
Explanation:
21+
const f = createHelloWorld();
22+
f({}, null, 42); // "Hello World"
23+
24+
Any arguments could be passed to the function but it should still always return "Hello World".
25+
26+
27+
Constraints:
28+
29+
0 <= args.length <= 10
30+
31+
32+
33+
*/
34+
35+
36+
/* -------------------Solution---------------------- */
37+
38+
/* @return {Function}
39+
*/
40+
var createHelloWorld = function () {
41+
42+
return function (...args) {
43+
return "Hello World";
44+
}
45+
};
46+
47+
const f = createHelloWorld();
48+
console.log(f());; // "Hello World"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /