2.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
acda2fb1324d9b0fa741e6b5 | Confirma el final | 5 | 16006 | confirm-the-ending |
--description--
Evalúa si una cadena (primer argumento, str
) termina con la cadena de destino dada (segundo argumento, target
).
Este desafío puede resolverse con el método .endsWith()
, que fue introducido en ES2015. Pero para el propósito de este desafío, nos gustaría que usaras uno de los métodos de subcadena de JavaScript en su lugar.
--hints--
confirmEnding("Bastian", "n")
debe devolver true
.
assert(confirmEnding('Bastian', 'n') === true);
confirmEnding("Congratulation", "on")
debe devolver true
.
assert(confirmEnding('Congratulation', 'on') === true);
confirmEnding("Connor", "n")
debe devolver false
.
assert(confirmEnding('Connor', 'n') === false);
confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")
debe devolver 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")
debe devolver true
.
assert(confirmEnding('He has to give me a new name', 'name') === true);
confirmEnding("Open sesame", "same")
debe devolver true
.
assert(confirmEnding('Open sesame', 'same') === true);
confirmEnding("Open sesame", "sage")
debe devolver false
.
assert(confirmEnding('Open sesame', 'sage') === false);
confirmEnding("Open sesame", "game")
debe devolver 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")
debe devolver 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")
debe devolver true
.
assert(confirmEnding('Abstraction', 'action') === true);
Tu código no debe usar el método incorporado .endsWith()
para resolver el desafío.
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");