DEV Community

Cover image for LeetCode 2667. Create Hello World Function (Easy)
48

LeetCode 2667. Create Hello World Function (Easy)

Could you solve the last LeetCode problem? πŸ€“ Here's another one, the simplest of the simplest. But hey, we all have to start somewhere.

Starting point

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

My Submission

Let's take a look at my code. Yours maybe looks different, and that's okay. Everyone has their own approach.

var createHelloWorld = function() {
     return function() {
        return "Hello World"
     }
 }
Enter fullscreen mode Exit fullscreen mode

What happens here?

var createHelloWorld = function() {

 }
Enter fullscreen mode Exit fullscreen mode

What was given by LeetCode was the outer declaration, the initialization of var createHelloWorld, which was assigned a function.

πŸ‘» Note: I personally never use var when declaring a variable, I always opt for let or const, but since this was the default, I'll keep it that way (there's nothing really wrong with using var).

Return a function

In the description it is said that we should return a function, which I did by writing

return function() {

}
Enter fullscreen mode Exit fullscreen mode

Always return "Hello World"

By adding

return "Hello World"
Enter fullscreen mode Exit fullscreen mode

inside the function, the string "Hello World" will be returned, no matter which argument the function may get.


In general, I am bad at explaining technical stuff. So any advice is welcome to improve my explanation skills πŸ™πŸ½.

Runner H image

Ask Once. Get a Day Trip, Booked & Budgeted.

Want a kid-friendly Paris itinerary with a €100 limit? Runner H books, maps, plans, and syncs it all. Works with Google Maps, Airbnb, Docs & more.

Try Runner H

Top comments (0)

Build seamlessly, securely, and flexibly with MongoDB Atlas. Try free.

Build seamlessly, securely, and flexibly with MongoDB Atlas. Try free.

MongoDB Atlas lets you build and run modern apps in 125+ regions across AWS, Azure, and Google Cloud. Multi-cloud clusters distribute data seamlessly and auto-failover between providers for high availability and flexibility. Start free!

Learn More

πŸ‘‹ Kindness is contagious

Explore this practical breakdown on DEV’s open platform, where developers from every background come together to push boundaries. No matter your experience, your viewpoint enriches the conversation.

Dropping a simple β€œthank you” or question in the comments goes a long way in supporting authorsβ€”your feedback helps ideas evolve.

At DEV, shared discovery drives progress and builds lasting bonds. If this post resonated, a quick nod of appreciation can make all the difference.

Okay