Hi all,
I’m tackling the confirmEnding challenge in Basic Algorithm Scripting and decided to make two arrays:
- an array of each letter from the target: […target]
- an array of the last letters of the str argument, equal in length to that of the target.
The code is doing what I want, in that if you pass the arguments (‘Chair’, ‘ir’) you get two identical arrays of [‘i’, ‘r’], and if you pass (‘Chair’, ‘xx’) you get one array of [‘i’, ‘r’] and the other of [‘x’, ‘x’]
But in my last step of code when I run an equality check of the arrays, it always returns false, even if they are identical. Hope this question makes sense and here’s the code below. Please advise.
function confirmEnding(str, target) {
let targetArr = []
let targetBreakdown = [...target];
for (let i = str.length - target.length; i < str.length; i++){
targetArr.push(str[i])
}
return targetBreakdown === targetArr
}
console.log(confirmEnding("Open sesame", "same"));