forked from mihaifm/linq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.js
More file actions
executable file
·87 lines (76 loc) · 3.05 KB
/
join.js
File metadata and controls
executable file
·87 lines (76 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var {test, testModule, deepEqual} = require('./testutils.js')
var Enumerable = require('../linq.min');
testModule("Join");
test("join", function ()
{
var math = { yamada: 100, tanaka: 80, yoshida: 94 };
var english = { yamada: 73, yoshida: 26, tanaka: 99 };
let actual = Enumerable.from(math)
.join(english, "outer=>outer.key", "inner=>inner.key",
"o,i=>{Name:o.key,Math:o.value,English:i.value}")
.toArray();
let expected = [{ Name: "yamada", Math: 100, English: 73 },
{ Name: "tanaka", Math: 80, English: 99 },
{ Name: "yoshida", Math: 94, English: 26}];
deepEqual(actual, expected);
actual = Enumerable.from(math)
.join(english, "outer=>outer", "inner=>inner",
"o,i=>{Name:o.key,Math:o.value,English:i.value}", "$.key")
.toArray();
expected = [{ Name: "yamada", Math: 100, English: 73 },
{ Name: "tanaka", Math: 80, English: 99 },
{ Name: "yoshida", Math: 94, English: 26}];
deepEqual(actual, expected);
actual = Enumerable.from(math)
.join(english, "outer=>outer.key", "inner=>inner.key",
"(o,i)=>{return {Name:o.key, Math:o.value, English:i.value}}")
.toArray();
expected = [{ Name: "yamada", Math: 100, English: 73 },
{ Name: "tanaka", Math: 80, English: 99 },
{ Name: "yoshida", Math: 94, English: 26}];
deepEqual(actual, expected);
actual = Enumerable.from(math)
.join(english, "outer=>outer.key", "inner=>inner.key",
"(o,i)=>{returnVal: o.key}")
.toArray();
expected = [{ returnVal: "yamada" }, { returnVal: "tanaka" }, { returnVal: "yoshida"}];
deepEqual(actual, expected);
});
test("groupJoin", function ()
{
var array1 = [3, 3, 4, 5, 6];
var array2 = [2, 4, 5, 6, 6];
let actual = Enumerable.from(array1)
.groupJoin(array2, " i => i", " i => i",
function (outer, collection)
{
return {
outer: outer,
collection: collection.toArray()
}
})
.toArray();
let expected = [{ outer: 3, collection: [] },
{ outer: 3, collection: [] },
{ outer: 4, collection: [4] },
{ outer: 5, collection: [5] },
{ outer: 6, collection: [6, 6]}];
deepEqual(actual, expected);
actual = Enumerable.from(array1)
.groupJoin(array2, " i => i", " i => i",
function (outer, collection)
{
return {
outer: outer,
collection: collection.toArray()
}
},
function (key) { return key % 2 == 0; })
.toArray();
expected = [{ outer: 3, collection: [5] },
{ outer: 3, collection: [5] },
{ outer: 4, collection: [2, 4, 6, 6] },
{ outer: 5, collection: [5] },
{ outer: 6, collection: [2, 4, 6, 6]}];
deepEqual(actual, expected);
});