2.8 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| acda2fb1324d9b0fa741e6b5 | تيقن من الأخير | 1 | 16006 | confirm-the-ending |
--description--
تحقق مما إذا كان المقطع النصي (string) (المعطى (argument) الأولى str) أخر المقطع النصي المطلوب (المعطى الثاني target).
يمكنك حل هذا التحدي بطريقة .endsWith()، التي تم تقديمها في ES2015. لكن لغرض هذا التحدي، نود أن تستخدموا واحدة من طرق subnstrings فى 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);
برنامجك يجب ألا يستخدم طريقة مبنية داخلياً (built-in method) باسم .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");