3.0 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| acda2fb1324d9b0fa741e6b5 | Підтвердження закінчення | 1 | 16006 | confirm-the-ending |
--description--
Перевірте, чи рядок (перший аргумент, str) закінчується заданим цільовим рядком (другий аргумент, target).
Це завдання можна вирішити за допомогою методу .endsWith(), який був введений в ES2015. Але ми б хотіли, щоб ви використали один із методів підрядків JavaScript.
--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");