freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../basic-algorithm-scripting/confirm-the-ending.md

114 lines
2.6 KiB
Markdown
Raw Normal View History

---
id: acda2fb1324d9b0fa741e6b5
title: Confirmar o final
challengeType: 1
forumTopicId: 16006
dashedName: confirm-the-ending
---
# --description--
2021-07-10 04:23:54 +00:00
Verifique se uma string (primeiro argumento, `str`) termina com a sequência de caracteres de destino fornecida (segundo argumento, `target`).
Este desafio *pode ser resolvido* com o método `.endsWith()`, que foi introduzido na ES2015. Para este desafio, entretanto, gostaríamos que você usasse um dos métodos de substring JavaScript.
# --hints--
2021-07-10 04:23:54 +00:00
`confirmEnding("Bastian","n")` deve retornar `true`.
```js
assert(confirmEnding('Bastian', 'n') === true);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("Congratulation","on")` deve retornar `true`.
```js
assert(confirmEnding('Congratulation', 'on') === true);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("Connor","n")` deve retornar `false`.
```js
assert(confirmEnding('Connor', 'n') === false);
```
`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` deve retornar `false`.
```js
assert(
confirmEnding(
'Walking on water and developing software from a specification are easy if both are frozen',
'specification'
) === false
);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("He has to give me a new name","name")` deve retornar `true`.
```js
assert(confirmEnding('He has to give me a new name', 'name') === true);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("Open sesame","same")` deve retornar `true`.
```js
assert(confirmEnding('Open sesame', 'same') === true);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("Open sesame", "sage")` deve retornar `false`.
```js
assert(confirmEnding('Open sesame', 'sage') === false);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("Open sesame","game")` deve retornar `false`.
```js
assert(confirmEnding('Open sesame', 'game') === false);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")` deve retornar `false`.
```js
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
);
```
2021-07-10 04:23:54 +00:00
`confirmEnding("Abstraction", "action")` deve retornar `true`.
```js
assert(confirmEnding('Abstraction', 'action') === true);
```
Seu código não deve usar o método integrado `.endsWith()` para resolver o desafio.
```js
assert(!/\.endsWith\(.*?\)\s*?;?/.test(code) && !/\['endsWith'\]/.test(code));
```
# --seed--
## --seed-contents--
```js
function confirmEnding(str, target) {
return str;
}
confirmEnding("Bastian", "n");
```
# --solutions--
```js
function confirmEnding(str, target) {
return str.substring(str.length - target.length) === target;
}
confirmEnding("Bastian", "n");
```