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

2.6 KiB

id title challengeType forumTopicId dashedName
acda2fb1324d9b0fa741e6b5 Confirmar o final 1 16006 confirm-the-ending

--description--

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--

confirmEnding("Bastian","n") deve retornar true.

assert(confirmEnding('Bastian', 'n') === true);

confirmEnding("Congratulation","on") deve retornar true.

assert(confirmEnding('Congratulation', 'on') === true);

confirmEnding("Connor","n") deve retornar false.

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.

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") deve retornar true.

assert(confirmEnding('He has to give me a new name', 'name') === true);

confirmEnding("Open sesame","same") deve retornar true.

assert(confirmEnding('Open sesame', 'same') === true);

confirmEnding("Open sesame", "sage") deve retornar false.

assert(confirmEnding('Open sesame', 'sage') === false);

confirmEnding("Open sesame","game") deve retornar 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") deve retornar 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") deve retornar true.

assert(confirmEnding('Abstraction', 'action') === true);

Seu código não deve usar o método integrado .endsWith() para resolver o desafio.

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");