FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Find Last Index

15mins

Implement a function findLastIndex(array, predicate) that returns the index of the last element in an array that satisfies the provided testing function.

  • array: The array to search.
  • predicate: A function that receives an element and returns a boolean.

If no element satisfies the predicate, return -1.

Example

findLastIndex([5, 12, 8, 130, 44], x => x > 10); // 4 findLastIndex(['apple', 'banana', 'cherry'], x => x.startsWith('b')); // 1 findLastIndex([1, 3, 5], x => x % 2 === 0); // -1

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests