FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Drop Right While

15mins

Implement a function dropRightWhile(array, predicate) that removes elements from the end of an array until the predicate returns false.

  • array: The array to iterate over.
  • predicate: A function invoked with each element, index, and the whole array. Stop dropping when predicate returns false.

Example

dropRightWhile([1, 2, 3, 4], n => n > 2); // [1, 2] dropRightWhile([1, 2, 3, 4], n => n < 4); // [1, 2, 3, 4]

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests