Skip to Main Content

Drop While

Problem URL:Drop While

My Solution

TypeScript

const dropWhile = <T>(
  array: Array<T>,
  predicate: (value: T, index: number, array: Array<T>) => boolean
): Array<T> => {
  let i = 0;

  while (predicate(array[i], i, array) && i < array.length) {
    i += 1;
  }

  return array.slice(i);
};

Let's Connect

Twitter GitHub LinkedIn