From cc7a1fe085cd4a507dd92b4e64b26d8b5a146def Mon Sep 17 00:00:00 2001 From: Brandon McConnell Date: Sat, 19 Nov 2022 16:17:47 -0500 Subject: [PATCH] Resolves insertion order mismatch in array-union examples (#503) --- README.md | 2 +- md-variables.json | 2 +- packages/array-union/README.md | 2 +- packages/array-union/index.js | 2 +- packages/array-union/index.mjs | 2 +- test/array-union/index.js | 8 ++++++++ 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 85f9a6a69..92eccd9f0 100644 --- a/README.md +++ b/README.md @@ -1507,7 +1507,7 @@ Returns the union of two arrays ```js import union from 'just-union'; -union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 3, 4, 5, 6] +union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4] ``` ### [just-zip-it](https://www.npmjs.com/package/just-zip-it) diff --git a/md-variables.json b/md-variables.json index 8af4bfc01..9153ae298 100644 --- a/md-variables.json +++ b/md-variables.json @@ -387,7 +387,7 @@ "examples": [ "import union from 'just-union';", "", - "union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 3, 4, 5, 6]" + "union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4]" ] }, "just-unique": { diff --git a/packages/array-union/README.md b/packages/array-union/README.md index 0f4709020..de20f901c 100644 --- a/packages/array-union/README.md +++ b/packages/array-union/README.md @@ -20,5 +20,5 @@ Returns the union of two arrays ```js import union from 'just-union'; -union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 3, 4, 5, 6] +union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4] ``` diff --git a/packages/array-union/index.js b/packages/array-union/index.js index b5b48577e..e5c4d8389 100644 --- a/packages/array-union/index.js +++ b/packages/array-union/index.js @@ -1,7 +1,7 @@ module.exports = union; /* - union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 3, 4, 5, 6] + union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4] */ function union(arr1, arr2) { diff --git a/packages/array-union/index.mjs b/packages/array-union/index.mjs index fde9daffa..a4ede280d 100644 --- a/packages/array-union/index.mjs +++ b/packages/array-union/index.mjs @@ -1,7 +1,7 @@ var arrayUnion = union; /* - union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 3, 4, 5, 6] + union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4] */ function union(arr1, arr2) { diff --git a/test/array-union/index.js b/test/array-union/index.js index e45b7bc89..1ed6cceb9 100644 --- a/test/array-union/index.js +++ b/test/array-union/index.js @@ -25,6 +25,14 @@ test('does not mutate', function(t) { t.end(); }); +test('respects insertion order', function(t) { + t.plan(1); + var arr1 = [1, 2, 5, 6]; + var arr2 = [2, 3, 4, 6]; + t.deepEqual(union(arr1, arr2), [1, 2, 5, 6, 3, 4]); + t.end(); +}); + test("throws if first two arguments aren't arrays", function(t) { t.plan(8); var arr1 = [1, 2, 3, 4, 5];