diff --git a/benchmarks/bundle-size/difference.spec.ts b/benchmarks/bundle-size/difference.spec.ts index a3522fb7..3317d84c 100644 --- a/benchmarks/bundle-size/difference.spec.ts +++ b/benchmarks/bundle-size/difference.spec.ts @@ -11,4 +11,9 @@ describe('difference bundle size', () => { const bundleSize = await getBundleSize('es-toolkit', 'difference'); expect(bundleSize).toMatchInlineSnapshot(`90`); }); + + it('es-toolkit/compat', async () => { + const bundleSize = await getBundleSize('es-toolkit/compat', 'difference'); + expect(bundleSize).toMatchInlineSnapshot(`433`); + }); }); diff --git a/docs/ja/reference/array/difference.md b/docs/ja/reference/array/difference.md index c36d4676..a1cb93f6 100644 --- a/docs/ja/reference/array/difference.md +++ b/docs/ja/reference/array/difference.md @@ -32,6 +32,28 @@ const result = difference(array1, array2); // 2と4は両方の配列に存在するため結果から除外され、result変数には[1, 3, 5]が割り当てられます。 ``` +## Lodashとの互換性 + +`es-toolkit/compat`から`difference`をインポートすると、lodashと互換性があります。 + +- `difference`は最初の配列と比較するために複数の配列を受け入れることができます。 +- `difference`は引数として配列のようなオブジェクトを受け入れることができます。 + +```typescript +import { difference } from 'es-toolkit/compat'; + +const array1 = [1, 2, 3, 4, 5]; +const array2 = [2, 4]; +const array3 = [5, 6]; +const result = difference(array1, array2, array3); +// 2、4、5は少なくとも1つの配列に存在するため、結果から除外され、result変数には[1, 3]が割り当てられます。 + +const arrayLike1 = { 0: 1, 1: 2, 2: 3, length: 3 }; +const arrayLike2 = { 0: 2, 1: 4, length: 2 }; +const result2 = difference(arrayLike1, arrayLike2); +// 2は両方の配列のようなオブジェクトに存在するため、結果から除外され、result2変数には[1, 3]が割り当てられます。 +``` + ## パフォーマンス比較 | | [Bundle Size](../../bundle-size.md) | [Performance](../../performance.md) | diff --git a/docs/ko/reference/array/difference.md b/docs/ko/reference/array/difference.md index f4dedddb..c3cf209f 100644 --- a/docs/ko/reference/array/difference.md +++ b/docs/ko/reference/array/difference.md @@ -32,6 +32,28 @@ const result = difference(array1, array2); // 2와 4는 두 배열 모두에 있기 때문에 결과에서 제외되고, result 변수에는 [1, 3, 5]가 할당되어요. ``` +## Lodash 호환성 + +`es-toolkit/compat`에서 `difference`를 가져오면 lodash와 호환돼요. + +- `difference`는 첫 번째 배열과 비교하기 위해 여러 배열을 받을 수 있어요. +- `difference`는 유사 배열 객체를 인수로 받을 수 있어요. + +```typescript +import { difference } from 'es-toolkit/compat'; + +const array1 = [1, 2, 3, 4, 5]; +const array2 = [2, 4]; +const array3 = [5, 6]; +const result = difference(array1, array2, array3); +// 2, 4, 5는 적어도 하나의 배열에 있기 때문에 결과에서 제외되고, result 변수에는 [1, 3]가 할당되어요. + +const arrayLike1 = { 0: 1, 1: 2, 2: 3, length: 3 }; +const arrayLike2 = { 0: 2, 1: 4, length: 2 }; +const result2 = difference(arrayLike1, arrayLike2); +// 2는 두 유사 배열 객체에 있기 때문에 결과에서 제외되고, result2 변수에는 [1, 3]가 할당되어요. +``` + ## 성능 비교 | | [번들 사이즈](../../bundle-size.md) | [성능](../../performance.md) | diff --git a/docs/reference/array/difference.md b/docs/reference/array/difference.md index d0c5a3e7..20a1703b 100644 --- a/docs/reference/array/difference.md +++ b/docs/reference/array/difference.md @@ -33,6 +33,28 @@ const result = difference(array1, array2); // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result. ``` +## Lodash Compatibility + +Import `difference` from `es-toolkit/compat` for full compatibility with lodash. + +- `difference` can accept multiple arrays to be compared against the first array. +- `difference` can accept array-like objects as arguments. + +```typescript +import { difference } from 'es-toolkit/compat'; + +const array1 = [1, 2, 3, 4, 5]; +const array2 = [2, 4]; +const array3 = [5, 6]; +const result = difference(array1, array2, array3); +// result will be [1, 3] since 2, 4, and 5 are in at least one of the arrays and are excluded from the result. + +const arrayLike1 = { 0: 1, 1: 2, 2: 3, length: 3 }; +const arrayLike2 = { 0: 2, 1: 4, length: 2 }; +const result2 = difference(arrayLike1, arrayLike2); +// result2 will be [1, 3] since 2 is in both array-like objects and is excluded from the result. +``` + ## Performance Comparison | | [Bundle Size](../../bundle-size.md) | [Performance](../../performance.md) | diff --git a/docs/zh_hans/reference/array/difference.md b/docs/zh_hans/reference/array/difference.md index 0d3baf8f..d050f58e 100644 --- a/docs/zh_hans/reference/array/difference.md +++ b/docs/zh_hans/reference/array/difference.md @@ -32,6 +32,28 @@ const result = difference(array1, array2); // 结果将是 [1, 3, 5],因为 2 和 4 都在两个数组中,所以它们被排除在结果之外。 ``` +## Lodash 兼容性 + +从 `es-toolkit/compat` 导入 `difference` 以获得与 lodash 的完全兼容性。 + +- `difference` 可以接受多个数组,用于与第一个数组进行比较。 +- `difference` 可以接受类数组对象作为参数。 + +```typescript +import { difference } from 'es-toolkit/compat'; + +const array1 = [1, 2, 3, 4, 5]; +const array2 = [2, 4]; +const array3 = [5, 6]; +const result = difference(array1, array2, array3); +// 结果将是 [1, 3],因为 2、4 和 5 至少在一个数组中,所以它们被排除在结果之外。 + +const arrayLike1 = { 0: 1, 1: 2, 2: 3, length: 3 }; +const arrayLike2 = { 0: 2, 1: 4, length: 2 }; +const result2 = difference(arrayLike1, arrayLike2); +// 结果将是 [1, 3],因为 2 在两个类数组对象中,所以它被排除在结果之外。 +``` + ## 性能对比 | | [包大小](../../bundle-size.md) | [性能](../../performance.md) |