JS Built-ins
StringString.prototype.lastIndexOfbeginner

String.prototype.lastIndexOf() β€” not found returns -1

πŸ“– Usage Example
const str = 'abcabc'
str.lastIndexOf('a')    // β†’ 3
str.lastIndexOf('z')    // β†’ -1
str.lastIndexOf('b', 3) // β†’ 1

Use lastIndexOf() to find the index of the last occurrence of a substring, searching from right to left.

String.prototype.lastIndexOf() β€” Not Found

Challenge: Implement notPresent(str, sub) that returns true when sub is not in str.

notPresent('hello', 'xyz') // β†’ true
notPresent('hello', 'ell') // β†’ false
πŸ’‘ Hints (1)
  • β€’ `.lastIndexOf()` returns `-1` when not found, just like `.indexOf()`.