Skip to content

Commit

Permalink
out
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyan Totev committed Jul 5, 2023
1 parent 315383f commit 124d75a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 38 deletions.
36 changes: 24 additions & 12 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2918,21 +2918,23 @@ differenceWith<T1, T2>(
import { curry } from './curry.js'
import { _indexOf } from './equals.js'

export function differenceWithFn(fn, a, b) {
let willReturn = []
let [first, second] = a.length > b.length ? [a, b] : [b, a]
export function differenceWithFn(
fn, a, b
){
const willReturn = []
const [ first, second ] = a.length > b.length ? [ a, b ] : [ b, a ]

first.forEach(item => {
let hasItem = second.some(secondItem => fn(item, secondItem))
if (!hasItem && _indexOf(item, willReturn) === -1) {
const hasItem = second.some(secondItem => fn(item, secondItem))
if (!hasItem && _indexOf(item, willReturn) === -1){
willReturn.push(item)
}
})

return willReturn
}

export let differenceWith = curry(differenceWithFn)
export const differenceWith = curry(differenceWithFn)
```
</details>
Expand All @@ -2942,14 +2944,18 @@ export let differenceWith = curry(differenceWithFn)
<summary><strong>Tests</strong></summary>
```javascript
import { differenceWith } from './differenceWith'
import { differenceWith } from './differenceWith.js'

test('happy', () => {
var foo = [{a: 1}, {a: 2}, {a: 3}];
var bar = [{a: 3}, {a: 4}];
var fn = function(r, s) { return r.a === s.a; }
const result = differenceWith(fn, foo, bar)
expect(result).toEqual([{a: 1}, {a: 2}])
const foo = [ { a : 1 }, { a : 2 }, { a : 3 } ]
const bar = [ { a : 3 }, { a : 4 } ]
const fn = function (r, s){
return r.a === s.a
}
const result = differenceWith(
fn, foo, bar
)
expect(result).toEqual([ { a : 1 }, { a : 2 } ])
})
```
Expand Down Expand Up @@ -18422,6 +18428,12 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

8.1.0

- Fix input order of TS definitions for `R.propEq` method - [Issue #688](https://github.com/selfrefactor/rambda/issues/688)

- Add `R.differenceWith` method - [Issue #91](https://github.com/selfrefactor/rambdax/issues/91)

8.0.0

- handle falsy values in merge methods - https://github.com/ramda/ramda/pull/3222
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
8.1.0

- Fix input order of TS definitions for `R.propEq` method - [Issue #688](https://github.com/selfrefactor/rambda/issues/688)

- Add `R.differenceWith` method - [Issue #91](https://github.com/selfrefactor/rambdax/issues/91)

8.0.0

- handle falsy values in merge methods - https://github.com/ramda/ramda/pull/3222
Expand Down
6 changes: 5 additions & 1 deletion NEXT_VERSION_CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
> Idea of this file is to store CHANGELOG changes until MR is ready to be opened.
differenceWith
differenceWith

---
try omitPath as method instead of multiple paths
---
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2772,21 +2772,23 @@ differenceWith<T1, T2>(
import { curry } from './curry.js'
import { _indexOf } from './equals.js'

export function differenceWithFn(fn, a, b) {
let willReturn = []
let [first, second] = a.length > b.length ? [a, b] : [b, a]
export function differenceWithFn(
fn, a, b
){
const willReturn = []
const [ first, second ] = a.length > b.length ? [ a, b ] : [ b, a ]

first.forEach(item => {
let hasItem = second.some(secondItem => fn(item, secondItem))
if (!hasItem && _indexOf(item, willReturn) === -1) {
const hasItem = second.some(secondItem => fn(item, secondItem))
if (!hasItem && _indexOf(item, willReturn) === -1){
willReturn.push(item)
}
})

return willReturn
}

export let differenceWith = curry(differenceWithFn)
export const differenceWith = curry(differenceWithFn)
```
</details>
Expand All @@ -2796,14 +2798,18 @@ export let differenceWith = curry(differenceWithFn)
<summary><strong>Tests</strong></summary>
```javascript
import { differenceWith } from './differenceWith'
import { differenceWith } from './differenceWith.js'

test('happy', () => {
var foo = [{a: 1}, {a: 2}, {a: 3}];
var bar = [{a: 3}, {a: 4}];
var fn = function(r, s) { return r.a === s.a; }
const result = differenceWith(fn, foo, bar)
expect(result).toEqual([{a: 1}, {a: 2}])
const foo = [ { a : 1 }, { a : 2 }, { a : 3 } ]
const bar = [ { a : 3 }, { a : 4 } ]
const fn = function (r, s){
return r.a === s.a
}
const result = differenceWith(
fn, foo, bar
)
expect(result).toEqual([ { a : 1 }, { a : 2 } ])
})
```
Expand Down Expand Up @@ -17146,6 +17152,12 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

8.1.0

- Fix input order of TS definitions for `R.propEq` method - [Issue #688](https://github.com/selfrefactor/rambda/issues/688)

- Add `R.differenceWith` method - [Issue #91](https://github.com/selfrefactor/rambdax/issues/91)

8.0.0

- handle falsy values in merge methods - https://github.com/ramda/ramda/pull/3222
Expand Down
8 changes: 4 additions & 4 deletions dist/rambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,17 +728,17 @@ function difference(a, b) {
}

function differenceWithFn(fn, a, b) {
let willReturn = [];
let [first, second] = a.length > b.length ? [a, b] : [b, a];
const willReturn = [];
const [first, second] = a.length > b.length ? [a, b] : [b, a];
first.forEach(item => {
let hasItem = second.some(secondItem => fn(item, secondItem));
const hasItem = second.some(secondItem => fn(item, secondItem));
if (!hasItem && _indexOf(item, willReturn) === -1) {
willReturn.push(item);
}
});
return willReturn;
}
let differenceWith = curry(differenceWithFn);
const differenceWith = curry(differenceWithFn);

function dissoc(prop, obj) {
if (arguments.length === 1) return _obj => dissoc(prop, _obj);
Expand Down
6 changes: 3 additions & 3 deletions rambda.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="./index.d.ts" />
export * from './src/F.js'
export * from './src/T.js'
export * from './src/add.js'
export * from './src/adjust.js'
export * from './src/all.js'
Expand Down Expand Up @@ -43,7 +45,6 @@ export * from './src/endsWith.js'
export * from './src/eqProps.js'
export * from './src/equals.js'
export * from './src/evolve.js'
export * from './src/F.js'
export * from './src/filter.js'
export * from './src/find.js'
export * from './src/findIndex.js'
Expand Down Expand Up @@ -129,8 +130,8 @@ export * from './src/prop.js'
export * from './src/propEq.js'
export * from './src/propIs.js'
export * from './src/propOr.js'
export * from './src/props.js'
export * from './src/propSatisfies.js'
export * from './src/props.js'
export * from './src/range.js'
export * from './src/reduce.js'
export * from './src/reject.js'
Expand All @@ -149,7 +150,6 @@ export * from './src/startsWith.js'
export * from './src/subtract.js'
export * from './src/sum.js'
export * from './src/symmetricDifference.js'
export * from './src/T.js'
export * from './src/tail.js'
export * from './src/take.js'
export * from './src/takeLast.js'
Expand Down
14 changes: 8 additions & 6 deletions src/differenceWith.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { curry } from './curry.js'
import { _indexOf } from './equals.js'

export function differenceWithFn(fn, a, b) {
let willReturn = []
let [first, second] = a.length > b.length ? [a, b] : [b, a]
export function differenceWithFn(
fn, a, b
){
const willReturn = []
const [ first, second ] = a.length > b.length ? [ a, b ] : [ b, a ]

first.forEach(item => {
let hasItem = second.some(secondItem => fn(item, secondItem))
if (!hasItem && _indexOf(item, willReturn) === -1) {
const hasItem = second.some(secondItem => fn(item, secondItem))
if (!hasItem && _indexOf(item, willReturn) === -1){
willReturn.push(item)
}
})

return willReturn
}

export let differenceWith = curry(differenceWithFn)
export const differenceWith = curry(differenceWithFn)

0 comments on commit 124d75a

Please sign in to comment.