Basic Algorithm Scripting - Confirm the Ending

To end whit this solution I started think in reverse.
First I split the str to it bring me a new arr of each letter of the stirng.
Then I create an empty array.
I loop for the array. Starting by the last index. And unshiting it to the empyt array. Then if the newArray were exactly as the target It return true; else false.

function confirmEnding(str, target) {
    let arr = str.split("");
    let arr_two = []; 
    for(let i = arr.length - 1; i >= 0; i--){
        arr_two.unshift(arr[i]);
        if(arr_two.join('') === target){
            return true; 
        }
    }
        return false; 
}
  console.log(confirmEnding("Congratulation", "on"));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Confirm the Ending

Link to the challenge:

Do you have a question?

The return true in the middle is suspicious to me.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.