sortBy
This commit is contained in:
@@ -87,6 +87,7 @@ class Kiss {
|
||||
// TODO some of these probably won't conflict, and could be passed as functions for a number of reasons
|
||||
"print" => Symbol("Prelude.print"),
|
||||
"sort" => Symbol("Prelude.sort"),
|
||||
"sortBy" => Symbol("Prelude.sortBy"),
|
||||
"groups" => Symbol("Prelude.groups"),
|
||||
"pairs" => Symbol("Prelude.pairs"),
|
||||
"reverse" => Symbol("Prelude.reverse"),
|
||||
|
@@ -196,6 +196,15 @@ class Prelude {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
public static function sortBy<T,U>(a:Array<T>, index:T->U, ?comp:(U, U) -> Int):kiss.List<T> {
|
||||
if (comp == null)
|
||||
comp = Reflect.compare;
|
||||
|
||||
return sort(a, (v1, v2) -> {
|
||||
return comp(index(v1), index(v2));
|
||||
});
|
||||
}
|
||||
|
||||
public static function groups<T>(a:Array<T>, size, extraHandling = Throw):kiss.List<kiss.List<T>> {
|
||||
var numFullGroups = Math.floor(a.length / size);
|
||||
var fullGroups = [
|
||||
|
Reference in New Issue
Block a user