array-mumu 0.2.0-rc.5

Array tools plugin for the Mumu ecosystem
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
extend("test")
extend("array")

describe("array:group_by", () => {
  it("groups by computed string key", () => {
    items = [[t:"x", v:1], [t:"y", v:2], [t:"x", v:3]]
    g = array:group_by(obj => obj["t"], items)
    expect_equal(g["x"], [[t:"x", v:1],[t:"x", v:3]])
    expect_equal(g["y"], [[t:"y", v:2]])
  })
  it("groups empty input to empty keyed array", () => {
    g = array:group_by(x => "k", [])
    expect_equal(type(g), "keyed_array")
  })
})