function endsWith(str, pattern) {
  return (
    str.lastIndexOf(pattern) === (str.length - pattern.length)
  );
}
Polyfill for `endsWith`

@param {string} str
@param {string} pattern
@return {boolean}