my code:
function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor
for (var x=0 ;x < str.length; x++) {
if (str.substring(str.length-x) === target.substring(target.length-4,target.length))
return true;
}
return false;
}
Hello, i used slice for solve the challenge.
Here is my code
function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor
return str.slice(-target.length) == target;
}
confirmEnding(“Bastian”, “n”);
As always here is my new way to do it
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str.substr(-target.length) === target;
}
My solution was pretty much the same as the basic code answer. However I did try to solve it with the .endWith() method as well. I’ll include that below for comparison.
Hi everyone, I solved this using the string method .includes() after I split the sentence/word into an array of words/letters. Do you think this is cheating or is this fine?
function confirmEnding(str, target) {
var splitStr;
if (str.includes(" "))
splitStr = str.split(" ");
else
splitStr = str.split("");
var lastPart = splitStr[splitStr.length - 1];
return lastPart.includes(target);
}
confirmEnding("Bastian", "n");
Hi all,This is how I did it.
function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor
var ne = str.substring(str.length -target.length);
if (ne === target){
return true;
}
return false;
}
function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor
var car = str.split(’’);
var cCar = target.split(’’);
if(target == str.substr( car.length - cCar.length))
return true;
else
return false;
}
confirmEnding(“He has to give me a new name”, “name”);
Would like to know what’s there to improve on this…