Skip to content

Commit

Permalink
feat: support difference, differenceWith
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Nov 12, 2024
1 parent 3b39052 commit 5064736
Show file tree
Hide file tree
Showing 69 changed files with 211 additions and 61 deletions.
27 changes: 27 additions & 0 deletions docs/array/difference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# difference

Creates an `array` of array values ​​that are not contained in other given arrays.

### Usage

```ts
import { difference } from 'rattail'

difference([1, 2, 3, 4], [2, 3])
// return [1, 4]
difference([1, 2, 3, 4], [2, 3], [3, 4])
// return [1]
```

### Arguments

| Arg | Type | Defaults |
| ----------- | -------------- | -------- |
| `arr` | `Array` | |
| `...values` | `Array<Array>` | |

### Return

| Type |
| ------- |
| `Array` |
28 changes: 28 additions & 0 deletions docs/array/differenceWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# differenceWith

Creates an array of array values ​​that are not contained in other given arrays, and supports custom comparison functions.

### Usage

```ts
import { difference } from 'rattail'

differenceWith([{ num: 1 }, { num: 2 }, { num: 3 }], [{ num: 2 }], (a, b) => a.num === b.num)
// return [{ num: 1 }, { num: 3 }]
differenceWith([{ num: 1 }, { num: 2 }, { num: 3 }], [{ num: 2 }], [{ num: 3 }], (a, b) => a.num === b.num)
// return [{ num: 1 }]
```

### Arguments

| Arg | Type | Defaults |
| ----------- | ------------------------- | -------- |
| `arr` | `Array` | |
| `...values` | `Array<Array>` | |
| `fn` | `(a: any, b: any) => any` | |

### Return

| Type |
| ------- |
| `Array` |
27 changes: 27 additions & 0 deletions docs/zh/array/difference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# difference

创建一个不包含在其他给定数组中的数组值的 `数组`

### 使用

```ts
import { difference } from 'rattail'

difference([1, 2, 3, 4], [2, 3])
// return [1, 4]
difference([1, 2, 3, 4], [2, 3], [3, 4])
// return [1]
```

### 参数

| 参数 | 类型 | 默认值 |
| ----------- | -------------- | ------ |
| `arr` | `Array` | |
| `...values` | `Array<Array>` | |

### 返回值

| 类型 |
| ------- |
| `Array` |
28 changes: 28 additions & 0 deletions docs/zh/array/differenceWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# differenceWith

创建一个不包含在其他给定数组中的数组值的数组,并支持自定义比较函数。

### 使用

```ts
import { difference } from 'rattail'

differenceWith([{ num: 1 }, { num: 2 }, { num: 3 }], [{ num: 2 }], (a, b) => a.num === b.num)
// return [{ num: 1 }, { num: 3 }]
differenceWith([{ num: 1 }, { num: 2 }, { num: 3 }], [{ num: 2 }], [{ num: 3 }], (a, b) => a.num === b.num)
// return [{ num: 1 }]
```

### 参数

| 参数 | 类型 | 默认值 |
| ----------- | ------------------------- | ------ |
| `arr` | `Array` | |
| `...values` | `Array<Array>` | |
| `fn` | `(a: any, b: any) => any` | |

### 返回值

| 类型 |
| ------- |
| `Array` |
2 changes: 1 addition & 1 deletion docs/zh/collection/clone-deep-with.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const value = cloneDeepWith(original, (val) => {
// value: { a: 2, b: { c: 4 } }
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :-------------------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/collection/clone-deep.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const value = cloneDeep(original)
// value: { a: 1, b: { c: 2 } }
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/function/call.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ call([(a, b) => a + b, (a, b) => a + b], 1, 2)
// return [3, 3]
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| --------- | :----------------------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/function/debounce.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const debouncedFn = debounce(() => {
window.addEventListener('resize', debouncedFn)
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :--------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/function/once.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn() // return 'initialized'
fn() // return 'initialized'
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ---- | :--------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/function/throttle.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const throttledFn = throttle(() => {
window.addEventListener('resize', throttledFn)
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :--------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/has-own.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hasOwn(obj, 'foo') // return true
hasOwn(obj, 'bar') // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-array-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isArrayBuffer } from 'rattail'
isArrayBuffer(new ArrayBuffer(8)) // return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isArray([]) // return true
isArray({}) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isBlob } from 'rattail'
isBlob(new Blob(['Hello, World!'], { type: 'text/plain' })) // return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-boolean.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isBoolean(true) // return true
isBoolean('rattail') // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-data-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isDataView } from 'rattail'
isDataView(new DataView(new ArrayBuffer(1))) // return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-date.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isDate(new Date()) // return true
isDate('2024-01-01') // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-dom-exception.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isDOMException(new DOMException('An error occurred')) // return true
isDOMException(new Error('An error occurred')) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ----- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-empty.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ isEmpty([]) // return true
isEmpty([1, 2, 3]) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-equal-with.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ isEqualWith([1, 2], ['1', '2'], (v1, v2) => {
// return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---------------------: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-equal.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ isEqual([1, 2, 3], [1, 2, 3])
// return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-error.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isError } from 'rattail'
isError(new Error('message')) // return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ----- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isFile(new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' }))
// return true
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isFunction(() => {}) // return true
isFunction(123) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isMap(new Map()) // return true
isMap({}) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-non-empty-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ isNonEmptyArray(null) // return false
isNonEmptyArray(undefined) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-nullish.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isNullish(undefined) // return true
isNullish(123) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isNumber(123) // return true
isNumber('rattail') // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-numeric.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isNumeric('456') // return true
isNumeric('rattail') // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isObject([]) // return true
isObject(null) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-plain-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isPlainObject({}) // return true
isPlainObject([]) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isPromise(Promise.resolve()) // return true
isPromise({}) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-reg-exp.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isRegExp(/abc/) // return true
isRegExp('abc') // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isSet(new Set()) // return true
isSet({}) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/general/is-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isString('rattail') // return true
isString(123) // return false
```

### 参数列表
### 参数

| 参数 | 类型 | 默认值 |
| ------- | :---: | -----: |
Expand Down
Loading

0 comments on commit 5064736

Please sign in to comment.