JS Built-ins
← Array80 / 226
ArrayArray.prototype.findLastintermediate

Array.prototype.findLast() β€” last short string

πŸ“– Usage Example
const words = ['cat', 'elephant', 'ant']
words.findLast(w => w.length > 3)  // β†’ 'elephant'

Use findLast() to find the last string in an array that meets a specific condition.

Array.prototype.findLast() β€” with strings

findLast() can be used to search for strings matching a length or content condition, scanning from the end.

Challenge: Implement findLastShort(strs, maxLen) that returns the last string with length < maxLen.

findLastShort(['hello', 'hi', 'world', 'ok'], 5) // β†’ 'ok'
findLastShort(['long string', 'another'], 3)     // β†’ undefined
πŸ’‘ Hints (2)
  • β€’ `s.length < maxLen` is strictly less than.
  • β€’ `findLast` scans from the end, so it returns the last qualifying string in order.