I'm basically trying to write a function which when called, performs the action of the endsWith() method
I've tried iterating through the original string and the string to be tested using for loops
function confirmEnding(str, target) {
let strWord = '';
let targetWord = '';
for (let i = (target.length - 1); i >= 0; i--) {
targetWord.concat(target.charAt(i))
for (let j = (str.length - 1); j >= 0; j--) {
strWord.concat(str.charAt(j));
}
}
if (strWord == targetWord) {
return true
} else {
return false
}
}
Now anytime i call the function, it returns true, what's wrong with my code?