KingNET.WebUI/Scripts/linqjs/test/grouping.js
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/// <reference path="testrunner.htm"/>
module("Grouping");
var fileList = ["temp.xls", "temp2.xls", "temp.pdf", "temp.jpg", "temp2.pdf", "temp3.xls"];
test("GroupBy", function ()
{
actual = Enumerable.From(fileList)
.GroupBy("file=>file.match(/\\.(.+$)/)[1]")
.Select("{Key:$.Key(),Value:$.ToArray()}")
.ToArray();
expected = [{ Key: "xls", Value: ["temp.xls", "temp2.xls", "temp3.xls"] },
{ Key: "pdf", Value: ["temp.pdf", "temp2.pdf"] },
{ Key: "jpg", Value: ["temp.jpg"]}];
deepEqual(actual, expected);
actual = Enumerable.From(fileList)
.GroupBy("file=>file.match(/\\.(.+$)/)[1]", "file=>file.match(/(^.+)\\..+$/)[1]")
.Select("{Key:$.Key(),Value:$.ToArray()}")
.ToArray();
expected = [{ Key: "xls", Value: ["temp", "temp2", "temp3"] },
{ Key: "pdf", Value: ["temp", "temp2"] },
{ Key: "jpg", Value: ["temp"]}];
deepEqual(actual, expected);
actual = Enumerable.From(fileList).GroupBy("file=>file.match(/\\.(.+$)/)[1]",
"file=>file",
"ext,group => {extension:ext,count:group.Count(),files:group.ToArray()}")
.ToArray();
expected = [{ extension: "xls", count: 3, files: ["temp.xls", "temp2.xls", "temp3.xls"] },
{ extension: "pdf", count: 2, files: ["temp.pdf", "temp2.pdf"] },
{ extension: "jpg", count: 1, files: ["temp.jpg"]}];
deepEqual(actual, expected);
var objects = [
{ Date: new Date(2000, 1, 1), Id: 1 },
{ Date: new Date(2010, 5, 5), Id: 2 },
{ Date: new Date(2000, 1, 1), Id: 3 }
]
var actual = Enumerable.From(objects)
.GroupBy("$.Date", "$.Id",
function (key, group) { return key.getFullYear() + "-" + group.ToString(',') },
function (key) { return key.toString() })
.ToArray();
expected = ["2000-1,3", "2010-2"]
deepEqual(actual, expected);
});
test("PartitionBy", function ()
{
actual = Enumerable.From(fileList)
.PartitionBy("file=>file.match(/\\.(.+$)/)[1]")
.Select("{Key:$.Key(),Value:$.ToArray()}")
.ToArray();
expected = [{ Key: "xls", Value: ["temp.xls", "temp2.xls"] },
{ Key: "pdf", Value: ["temp.pdf"] },
{ Key: "jpg", Value: ["temp.jpg"] },
{ Key: "pdf", Value: ["temp2.pdf"] },
{ Key: "xls", Value: ["temp3.xls"] }
后面还有 52 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。