Jump to content

Category talk:Wren-seq: Difference between revisions

→‎Source code: Added Lst.groupBy method.
(→‎Source code: Bug fix.)
(→‎Source code: Added Lst.groupBy method.)
Line 202:
}
return g
}
 
// Applies a function to each element of a list to produce a key and returns a map of each
// distinct key to a list of the corresponding elements. The latter retain their original
// order within the list and the key must be a value type.
static groupBy(a, fn) {
isList_(a)
var m = {}
for (e in a) {
var k = fn.call(e)
if (!m.containsKey(k)) {
m[k] = [e]
} else {
m[k].add(e)
}
}
return m
}
 
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.