The dropWhile Function
Description:
Yet another staple for the functional programmer. You have a sequence of values and some predicate for those values. You want to remove the longest prefix of elements such that the predicate is true for each element. We'll call this the dropWhile function. It accepts two arguments. The first is the sequence of values, and the second is the predicate function. The function does not change the value of the original sequence.
function isEven(num) {
return num % 2 === 0;
}
var seq = [2,4,6,8,1,2,5,4,3,2];
dropWhile(seq, isEven) // -> [1,2,5,4,3,2]
Your task is to implement the dropWhile function. If you've got a span function lying around, this is a one-liner! Alternatively, if you have a takeWhile function on your hands, then combined with the dropWhile function, you can implement the span function in one line. This is the beauty of functional programming: there are a whole host of useful functions, many of which can be implemented in terms of each other.
Similar Kata:
Stats:
Created | Mar 6, 2015 |
Published | Mar 6, 2015 |
Warriors Trained | 8179 |
Total Skips | 363 |
Total Code Submissions | 11626 |
Total Times Completed | 3470 |
JavaScript Completions | 1790 |
Haskell Completions | 231 |
CoffeeScript Completions | 19 |
C++ Completions | 271 |
C# Completions | 237 |
Python Completions | 880 |
C Completions | 115 |
Ruby Completions | 100 |
λ Calculus Completions | 17 |
OCaml Completions | 41 |
Factor Completions | 11 |
Lua Completions | 26 |
Total Stars | 86 |
% of votes with a positive feedback rating | 89% of 514 |
Total "Very Satisfied" Votes | 417 |
Total "Somewhat Satisfied" Votes | 77 |
Total "Not Satisfied" Votes | 20 |