diff --git a/LINQJS.code-workspace b/LINQJS.code-workspace new file mode 100644 index 0000000..bab1b7f --- /dev/null +++ b/LINQJS.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/linq.js b/linq.js index 29091b9..0be1f96 100644 --- a/linq.js +++ b/linq.js @@ -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 { diff --git a/test/join.js b/test/join.js index 48a3dc5..3070f35 100755 --- a/test/join.js +++ b/test/join.js @@ -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); +}); \ No newline at end of file