js confirm the last character algorithm challenge

Check whether a string (str) to a specified string (target) end.

If so, it returns true; if not, it returns false.

This challenge can be solved by .endsWith introduced in the ES2015 () method. But for the purposes of this challenge, we want you to use one of the sub JavaScript string method.


function confirmEnding(str, target) {

return str.endsWith(target);
}

confirmEnding("Bastian", "n");

Guess you like

Origin www.cnblogs.com/dobeco/p/11407074.html