Skip to content

Commit

Permalink
correct some error
Browse files Browse the repository at this point in the history
  • Loading branch information
miquik committed Mar 30, 2022
1 parent 8076962 commit 62c8c32
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions LINQJS.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {}
}
2 changes: 1 addition & 1 deletion linq.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ Enumerable.prototype.leftJoin = function (inner, outerKeySelector, innerKeySelec
const key = outerKeySelector(outerEnumerator.current());
innerElements = lookup.get(key).toArray();
// execute once if innerElements is NULL
if (innerElements == null) {
if (innerElements == null || innerElements.length == 0) {
return this.yieldReturn(resultSelector(outerEnumerator.current(), null));
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions test/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ test("groupJoin", function ()
{ outer: 6, collection: [2, 4, 6, 6]}];
deepEqual(actual, expected);
});

test("leftJoin", function ()
{
var math = { yamada: 100, tanaka: 80, yoshida: 94 };
var english = { yamada: 73, tanaka: 99 };
let actual = Enumerable.from(math)
.leftJoin(english, "outer=>outer.key", "inner=>inner.key",
(o,i) => ({Name:o.key,Math:o.value,English:i == null ? null : i.value}))
.toArray();
let expected = [{ Name: "yamada", Math: 100, English: 73 },
{ Name: "tanaka", Math: 80, English: 99 },
{ Name: "yoshida", Math: 94, English: null}];
deepEqual(actual, expected);

actual = Enumerable.from(math)
.leftJoin(english, "outer=>outer", "inner=>inner",
(o,i) => ({Name:o.key,Math:o.value,English:i == null ? null : i.value}),
"$.key")
.toArray();
expected = [{ Name: "yamada", Math: 100, English: 73 },
{ Name: "tanaka", Math: 80, English: 99 },
{ Name: "yoshida", Math: 94, English: null}];
deepEqual(actual, expected);
});

0 comments on commit 62c8c32

Please sign in to comment.