JS Built-ins
StringString.prototype.endsWithintermediate

String.prototype.endsWith() β€” endPosition parameter

πŸ“– Usage Example
const str = 'Hello, World!'
str.endsWith('!')        // β†’ true
str.endsWith('World')    // β†’ false
str.endsWith('World', 12) // β†’ true

Use endsWith() to check if a string ends with a specific suffix, with an optional end position.

String.prototype.endsWith() β€” endPosition

The optional second argument endPosition treats the string as if it only goes up to that index.

'Hello World'.endsWith('Hello', 5) // β†’ true

Challenge: Implement endsWithHello(str) that checks if the first 5 characters end with 'Hello'.

πŸ’‘ Hints (1)
  • β€’ `str.endsWith(search, endPos)` considers only `str.slice(0, endPos)`.