0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

文系(体育科)卒業の僕が、人並みのアルゴリズムを身につけるためにLeetCodeを初めてみました。
日本だとAtCoderが一般的なようですが、海外エンジニアへの憧れを持つ僕はLeetCodeを選びました。

フロントの言語しかほぼ触ったことがないのでJavaScriptでやっていこうと思います。

問題

2667. Create Hello World Function

問題文

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

初期コード

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

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

常に"Hello World"をリターンする新しい関数をリターンするcreateHelloWorldを作れば良さそうです。
実際に値を入れてみたケースも例として出ています。
CleanShot 2024-06-23 at 04.50.44@2x.jpg

流石に初見の僕でもこれは解けそう...!
今回は引数は関係ないのでとりあえずreturnを追加すればいいんじゃない?と思ったので下記のようにしてみた。

javascript
var createHelloWorld = function() {
    
    return function(...args) {
+        return "Hello World"        
    }
};

Submitボタンを押すと...どうやら成功したようです。
例1の空の配列を渡すケース、例2の[{},null,42]を渡すコードでテストがされるようです。

成功すると自分の順位が出るようです。

CleanShot 2024-06-23 at 04.59.00@2x.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?