Confirm the ending

Here is my solution. Wanted to use both methods and all the rules with the numbers that go with it.

function confirmEnding(str, target) {

      if(target.substring(0) === str.substr (-target.length)){
        return true;
      }
      else
        return false;
      
    }
    confirmEnding("Bastian", "n");

Check below code: It’s working fine

  var lastString = str.slice(str.length-target.length);
  return lastString == target;

I’ve made it like that:

function confirmEnding(str, target) {
return str.substr(str.length - target.length) === target;
}

confirmEnding(“Bastian”, “n”);

Hello friends here is my code, i did it, i am so happy, i was 3 hours thinking, its alive, its alive


function confirmEnding(str, target) {
var name = str.split(" ");
if(name.length===1){
var name1 = String(name);
var theLast = name1.substring(name1.length-1);
if(theLast===target){
return true;
}else{
return false;
}
/-----------------------------------------/
}else{
var word = name[name.length-1].substring(2,6);
if (name[name.length-1] === target){
return true;
}else if(word === target){
return true;
}else{
return false;
}

}

}

confirmEnding(“Open sesame”, “same”);

Hi, I tried to complete this is the simplest way possible (I was getting annoyed with loops being used for these challenges) I think it should work for most cases. =)

function confirmEnding(str, target) {

return str.substr(-target.length,target.length) === target;

}

confirmEnding(“Bastian”, “n”);

Hello, i found some thing ‘ez’ to do with simple array. It just compare each letter backward.
Make sure to have the length - 1 because of array index. If some thing is wrong, return false. If nothing wrong found in the foreach, it’s true.


function confirmEnding(str, target) {
	let targetLL = target.length;
	let strL = str.length - 1; //7 => 6 in array index
	let targetL = target.length - 1; //1 => 0 in array index
	
	for( let k = 0; k < targetLL; k++ ) {
		if( str[strL] !== target[targetL] ) {
			return false;
		}
		
		strL--;
		targetL--;
	}
	
	return true;
};

console.log( confirmEnding("Bastian", "n") );
console.log( confirmEnding("Congratulation", "on") );
console.log( confirmEnding("Connor", "n") );
console.log( confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") );
console.log( confirmEnding("He has to give me a new name", "name") );
console.log( confirmEnding("Open sesame", "same") );
console.log( confirmEnding("Open sesame", "pen") );
console.log( confirmEnding("Open sesame", "game") );
console.log( confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") );
console.log( confirmEnding("Abstraction", "action") );

Hi guys ,
this is just a simple Code for beginning //

function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor
for (i=0; i<str.length;i++){
if (target == str.substr(-i) || target == str.substr(i) ) {
return true;}

}
return false;

}

confirmEnding(“Bastian”, “n”);

Hi All,
This is my code :

function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor
var last_k="";
var str_map = str.split(" “);
var arr_string = str_map.length;
console.log(arr_string);
if(arr_string<2){
last_k = str_map.join(”").substr(-1);
if(last_k === target){
return true;
}else {
return false;
}
}else if(arr_string>=2){

  last_k= str_map[str_map.length-1];
console.log (last_k);
 if(last_k===target){
    return true;
  }else {
  return false;
  }
}

//return str_map;
}

confirmEnding(“He has to give me a new name”, “name”);
It’s working ok, with all of the situations, unless this : confirmEnding(“Open sesame”, “same”);

Some can help me? It’s an error of my code?

I’m guessing you are comparing the last word of the string to the target ans thus it is failing as even a match to the last portion of a word to the target should return true.

What I did for situations like this was to make a variable set to the length of the target:

var targetSize = target.length;

I then used

str.slice(-targetSize)

and checked how it compared to the target and if matched return true and if not, false.