Last active
January 13, 2019 11:07
-
-
Save apolopena/d2cb75459fcc815508af0ae810a74f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cars = [{make: "Honda", type: "truck"},{make: "Cadillac", type: "sedan"}, {make: "McLaren", type: "coup"}, {make: "Infinity", type: "coup"}]; | |
function reject(array, iteratorFunction) { | |
return array.filter(iteratorFunction); | |
} | |
var noCoups = reject(cars, function(car) { | |
return car.type !== "coup"; | |
}); | |
// or numbers reusing 'filter' to reverse the effect of filter (only push items that return false) | |
var numbers = [10,20,30]; | |
function reject2(array, iteratorFunction) { | |
return array.filter(function (item) { | |
return !iteratorFunction(item); | |
}); | |
} | |
var lessThan15 = reject2(numbers, function(n) { | |
return n > 15; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment