Hello,
I’ve tried this approach using a for loop to act as a filter to reject any false comparisons to the indexes in the string/ target. I saw the correct answers using basic data structure methods and felt like I way overcomplicated it, but I’d still like to see what part went wrong in my attempt:
function confirmEnding(str, target) {
let strLen = str.length-1;
let tarLen = target.length-1;
let result;
//below is the first index of the tar were looking for in the string
let first = strLen-tarLen;
// loop through the indexes from the first of target til last of the string
for(let i=0; i>tarLen;i++){
if (str[(first+i)] != target[i]){
result=false;
}
else {
result=true
};
return result;
}return result;
}
confirmEnding("Bastian", "n");
/*
len open sesame= 11, len same= 4;
so, for ^^, we'd need str index [strlen-tarLen] through index [srtlen];
checks this index = tar index0, then
then this index +1= tarindex1,
then this index+2 = tarindex2
*/
I found a link that did a variation of what I thought I was doing: the way I thought I did but it was locked and I’m still confused on how my code didn’t grasp that.
Thank you for your time and patience, Algorithms have knocked my momentum with learning JS off kilter and now I am worried that I’m giving up too easily, which I certainly don’t want.