DavidSzczesniak
10/27/2017 - 9:08 PM

Confirm the Ending

Confirms the last letter of a given word with the letter given. Call is (word, letter)

function confirmEnding(str, target) {
  // start = str - its last letter
  var start = str.length - (target.length);
  // If the last letter of str == the target return false
  if (str.substr(start, str.length) == target)  {
    return true;
  }
  // else return false
  else {
    return false;
  }
  
}

// Example call
confirmEnding("Bastian", "n");