Javascript String end(str, target)

Description

Javascript String end(str, target)


/*/* www. j  av  a  2  s. c  o m*/
Check if a string (first argument, str) ends with the given target string (second argument, target).
This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.

Here are some helpful links:
String.prototype.substr()
String.prototype.substring()
*/
function end(str, target) {
  if (str.substr(-target.length) == target) {
    return true;
  }
  else {   
    return false;
  }
}

end("Bastian", "n");



PreviousNext

Related