Files
2022-01-20 20:30:18 +01:00

2.9 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
acda2fb1324d9b0fa741e6b5 末尾の一致判定 5 16006 confirm-the-ending

--description--

文字列 (最初の引数、str) が与えられたターゲット文字列 (2 番目の引数、target) で終わるかどうかを確認してください。

このチャレンジは ES2015 で導入された .endsWith() メソッドを使用すれば解決できます。 しかし、ここでは代わりに JavaScript の substring メソッドを使用してください。

--hints--

confirmEnding("Bastian", "n")true を返す必要があります。

assert(confirmEnding('Bastian', 'n') === true);

confirmEnding("Congratulation", "on")true を返す必要があります。

assert(confirmEnding('Congratulation', 'on') === true);

confirmEnding("Connor", "n")false を返す必要があります。

assert(confirmEnding('Connor', 'n') === false);

confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")false を返す必要があります。

assert(
  confirmEnding(
    'Walking on water and developing software from a specification are easy if both are frozen',
    'specification'
  ) === false
);

confirmEnding("He has to give me a new name", "name")true を返す必要があります。

assert(confirmEnding('He has to give me a new name', 'name') === true);

confirmEnding("Open sesame", "same")true を返す必要があります。

assert(confirmEnding('Open sesame', 'same') === true);

confirmEnding("Open sesame", "sage")false を返す必要があります。

assert(confirmEnding('Open sesame', 'sage') === false);

confirmEnding("Open sesame", "game")false を返す必要があります。

assert(confirmEnding('Open sesame', 'game') === false);

confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")false を返す必要があります。

assert(
  confirmEnding(
    'If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing',
    'mountain'
  ) === false
);

confirmEnding("Abstraction", "action")true を返す必要があります。

assert(confirmEnding('Abstraction', 'action') === true);

このチャレンジを解決するプログラムでは、組み込みメソッド .endsWith() を使用しないでください。

assert(!/\.endsWith\(.*?\)\s*?;?/.test(code) && !/\['endsWith'\]/.test(code));

--seed--

--seed-contents--

function confirmEnding(str, target) {
  return str;
}

confirmEnding("Bastian", "n");

--solutions--

function confirmEnding(str, target) {
  return str.substring(str.length - target.length) === target;
}

confirmEnding("Bastian", "n");