JS Built-ins
← Array85 / 226
ArrayArray.prototype.findLastIndexintermediate

Array.prototype.findLastIndex() β€” last long string index

πŸ“– Usage Example
const words = ['hi', 'hello', 'hey']
words.findLastIndex(w => w.startsWith('h'))  // β†’ 2

Use findLastIndex() to find the last position of a string matching a pattern.

Array.prototype.findLastIndex() β€” strings

findLastIndex() works just as well with strings and any other element type.

Challenge: Implement lastLongIndex(strs, minLen) that returns the index of the last string with length >= minLen.

lastLongIndex(['hi', 'hello', 'world', 'ok'], 5) // β†’ 2
lastLongIndex(['a', 'b', 'c'], 3)                 // β†’ -1
πŸ’‘ Hints (2)
  • β€’ `>= minLen` is inclusive β€” strings of exactly `minLen` qualify.
  • β€’ `findLastIndex` scans from the end and returns the last qualifying index.