Skip to content

Commit

Permalink
Resolves insertion order mismatch in array-union examples (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonmcconnell authored Nov 19, 2022
1 parent 37f05f5 commit cc7a1fe
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion md-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/array-union/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```
2 changes: 1 addition & 1 deletion packages/array-union/index.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/array-union/index.mjs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions test/array-union/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit cc7a1fe

Please sign in to comment.