From 74bda8779471bde5bff9c7d7eb3283610fb624a8 Mon Sep 17 00:00:00 2001 From: Jean-Paul Gorman Date: Tue, 10 Oct 2017 12:58:46 +0100 Subject: [PATCH 1/2] Add without method Resolves #40 --- __tests__/without.js | 11 +++++++++++ index.d.ts | 1 + modules/without.js | 5 +++++ rambda.js | 1 + 4 files changed, 18 insertions(+) create mode 100644 __tests__/without.js create mode 100644 modules/without.js diff --git a/__tests__/without.js b/__tests__/without.js new file mode 100644 index 000000000..94658ccc4 --- /dev/null +++ b/__tests__/without.js @@ -0,0 +1,11 @@ +const R = require('../rambda') + +describe('without', () => { + it('should return a new list without values in the first argument ', () => { + const itemsToOmit = ['A', 'B', 'C'] + const collection = ['A', 'B', 'C', 'D', 'E', 'F'] + expect( + R.without(itemsToOmit, collection) + ).toEqual([ 'D', 'E', 'F' ]) + }) +}) diff --git a/index.d.ts b/index.d.ts index d199c6094..0d55d6323 100644 --- a/index.d.ts +++ b/index.d.ts @@ -381,6 +381,7 @@ declare namespace R { update(index: number, value: T): (list: T[]) => T[]; values(obj: T): Array; + without(listToOmit: any[], originalList: any[]): list: any[]; } } diff --git a/modules/without.js b/modules/without.js new file mode 100644 index 000000000..6392c12bc --- /dev/null +++ b/modules/without.js @@ -0,0 +1,5 @@ +import contains from './contains' + +export default function without(itemsToOmit, collection) { + return collection.reduce((accum, item) => !contains(item, itemsToOmit) ? accum.concat(item) : accum, []) +} diff --git a/rambda.js b/rambda.js index b7e6b3b05..471d5a57a 100644 --- a/rambda.js +++ b/rambda.js @@ -93,3 +93,4 @@ export { default as typedDefaultTo } from './modules/typedDefaultTo' export { default as uniq } from './modules/uniq' export { default as update } from './modules/update' export { default as values } from './modules/values' +export { default as without } from './modules/without' From a4c5955a4ddcd16c5b860f453ee613d2eb27d921 Mon Sep 17 00:00:00 2001 From: Jean-Paul Gorman Date: Tue, 10 Oct 2017 13:06:00 +0100 Subject: [PATCH 2/2] User internal reduce method --- modules/without.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/without.js b/modules/without.js index 6392c12bc..7dcd332d5 100644 --- a/modules/without.js +++ b/modules/without.js @@ -1,5 +1,6 @@ import contains from './contains' +import reduce from './reduce' export default function without(itemsToOmit, collection) { - return collection.reduce((accum, item) => !contains(item, itemsToOmit) ? accum.concat(item) : accum, []) + return reduce((accum, item) => !contains(item, itemsToOmit) ? accum.concat(item) : accum, [], collection) }