Skip to content

Commit

Permalink
filter-not exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
hayeah committed Aug 11, 2016
1 parent 049cb50 commit 038edd4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions filter/filter-not.js
@@ -0,0 +1,22 @@
/*
用 filter 实现 filterNot。 filterNot 保留不符合条件的元素。
*/


const { equal } = require("../equal");

function filterNot(array, test) {
return array.filter(o => !test(o));
}

equal(
filterNot([1, 2, 3, 2, 1], x => x === 1),
[2, 3, 2]
);

equal(
filterNot([1, -1, 2, -2, 3, -3], x => x > 0),
[-1, -2, -3]
);


0 comments on commit 038edd4

Please sign in to comment.