FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Drop While

15mins

Implement a function dropWhile(array, predicate) that removes elements from the beginning 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

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

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests