Confirm the Ending for string using split array

Tell us what’s happening:
test error : 2) confirmEnding(“Congratulation”, “on”)` should return true.
any help please?
if i uses reduceRight is good idea?

Your code so far


function confirmEnding(str, target) {
let arr = str.split("");
return arr[arr.length-1]==target ;
}

confirmEnding("Bastian", "n");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36.

Challenge: Confirm the Ending

Link to the challenge:

As you can see, you have a precise value hard-coded, -1.
But what if the string to confirm is longer, like in the test that’s failing?

With your code so far:

confirmEnding("Bob", "b") // true
confirmEnding("Bob", "ob") // false

Hope this helps :sparkles:

1 Like