From 54bc80968b09b5bd0e75d3cf96beb76180d47f4a Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 8 Jan 2018 16:40:46 +0200 Subject: [PATCH] Add reject --- snippets/reject.md | 17 +++++++++++++++++ tag_database | 1 + 2 files changed, 18 insertions(+) create mode 100644 snippets/reject.md diff --git a/snippets/reject.md b/snippets/reject.md new file mode 100644 index 00000000000..ce493dcdef1 --- /dev/null +++ b/snippets/reject.md @@ -0,0 +1,17 @@ +### reject + +Returns the elements of an array for which the passed function returns `false`. + +Use `Array.filter()` and the not operator (`!`) to return the elements in the array for which `fn` returns `false`. + +```js +const reject = (arr, fn) => arr.filter((e,i,arr) => !fn(e,i,arr)); +``` + +```js +const users = [ + { 'user': 'barney', 'age': 36, 'active': false }, + { 'user': 'fred', 'age': 40, 'active': true } +]; +reject(users, o => !o.active); // [{ 'user': 'fred', 'age': 40, 'active': true }] +``` diff --git a/tag_database b/tag_database index a9862093da4..dde249978ec 100644 --- a/tag_database +++ b/tag_database @@ -128,6 +128,7 @@ randomNumberInRange:math,utility,random readFileLines:node,array,string redirect:browser,url reducedFilter:array +reject:array,object,function remove:array reverseString:string,array RGBToHex:utility