Tell us what’s happening:
I was doing this practice and I finished it but i fill like my code is too long. I am pretty sure there is a even more simpler algorithm to complete this challenge. I would much appreciate it if anyone would tell me a simpler algorithm for this challenge.
And i am also really sorry for not naming my variables properly.
Your code so far
function confirmEnding(str, target) {
// “Never give up and good luck will find you.”
// – Falcor;
var f = str.split(’’);
var l=’’;
var k = 1;
for (var i = target.length;i>0;i–){
l+=f[(str.length-k)]
k++;
}
var n=l.split(’’);
n.reverse();
var u = n.join(’’);
if(target==u){
return true;
}else{
return false;
}
}
confirmEnding(“Bastian”, “an”);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending/