--- id: acda2fb1324d9b0fa741e6b5 title: Confirm the Ending localeTitle: Confirmar el final isRequired: true challengeType: 5 --- ## Description
Compruebe si una cadena (primer argumento, str ) termina con la cadena de destino dada (segundo argumento, target ). Este desafío se puede resolver con el método .endsWith() , que se introdujo en ES2015. Pero para el propósito de este desafío, nos gustaría que utilices uno de los métodos de subcadena de JavaScript. Recuerda usar Read-Search-Ask si te atascas. Escribe tu propio código.
## Instructions
## Tests
```yml tests: - text: ' confirmEnding("Bastian", "n") debe devolver verdadero.' testString: 'assert(confirmEnding("Bastian", "n") === true, "confirmEnding("Bastian", "n") should return true.");' - text: ' confirmEnding("Congratulation", "on") debe devolver verdadero.' testString: 'assert(confirmEnding("Congratulation", "on") === true, "confirmEnding("Congratulation", "on") should return true.");' - text: ' confirmEnding("Connor", "n") debe devolver falso.' testString: 'assert(confirmEnding("Connor", "n") === false, "confirmEnding("Connor", "n") should return false.");' - text: ' confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") debe devolver falso. testString: 'assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false, "confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") should return false.");' - text: ' confirmEnding("He has to give me a new name", "name") debe devolver verdadero.' testString: 'assert(confirmEnding("He has to give me a new name", "name") === true, "confirmEnding("He has to give me a new name", "name") should return true.");' - text: ' confirmEnding("Open sesame", "same") debe devolver verdadero.' testString: 'assert(confirmEnding("Open sesame", "same") === true, "confirmEnding("Open sesame", "same") should return true.");' - text: ' confirmEnding("Open sesame", "pen") debe devolver falso. testString: 'assert(confirmEnding("Open sesame", "pen") === false, "confirmEnding("Open sesame", "pen") should return false.");' - text: ' confirmEnding("Open sesame", "game") debe devolver falso. testString: 'assert(confirmEnding("Open sesame", "game") === false, "confirmEnding("Open sesame", "game") should return 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") debería devolver el valor falso ". 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, "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.");' - text: ' confirmEnding("Abstraction", "action") debe devolver verdadero.' testString: 'assert(confirmEnding("Abstraction", "action") === true, "confirmEnding("Abstraction", "action") should return true.");' - text: No use el método .endsWith() para resolver el desafío. testString: 'assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\["endsWith"\]/.test(code)), "Do not use the built-in method .endsWith() to solve the challenge.");' ```
## 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"); ```