--- id: acda2fb1324d9b0fa741e6b5 title: Confirm the Ending isRequired: true challengeType: 5 forumTopicId: 16006 localeTitle: Подтвердить завершение --- ## Description
Проверьте, заканчивается ли строка (первый аргумент, str ) заданной целевой строкой (второй аргумент, target ). Эта проблема может быть решена с помощью .endsWith() , который был введен в ES2015. Но для этой задачи мы хотели бы, чтобы вы использовали один из методов подстроки JavaScript. Не забудьте использовать Read-Search-Ask, если вы застряли. Напишите свой собственный код.
## Instructions
## Tests
```yml tests: - text: confirmEnding("Bastian", "n") should return true. testString: assert(confirmEnding("Bastian", "n") === true); - text: confirmEnding("Congratulation", "on") should return true. testString: assert(confirmEnding("Congratulation", "on") === true); - text: confirmEnding("Connor", "n") should return false. testString: assert(confirmEnding("Connor", "n") === false); - text: confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") should return false. testString: assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false); - text: confirmEnding("He has to give me a new name", "name") should return true. testString: assert(confirmEnding("He has to give me a new name", "name") === true); - text: confirmEnding("Open sesame", "same") should return true. testString: assert(confirmEnding("Open sesame", "same") === true); - text: confirmEnding("Open sesame", "pen") should return false. testString: assert(confirmEnding("Open sesame", "pen") === false); - text: confirmEnding("Open sesame", "game") should return false. testString: assert(confirmEnding("Open sesame", "game") === false); - text: confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") should return false. testString: 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); - text: confirmEnding("Abstraction", "action") should return true. testString: assert(confirmEnding("Abstraction", "action") === true); - text: Do not use the built-in method .endsWith() to solve the challenge. testString: assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\['endsWith'\]/.test(code))); ```
## Challenge Seed
```js function confirmEnding(str, target) { // "Never give up and good luck will find you." // -- Falcor return str; } confirmEnding("Bastian", "n"); ```
## Solution
```js function confirmEnding(str, target) { return str.substring(str.length - target.length) === target; } confirmEnding("Bastian", "n"); ```