on master help sign in
Add sort function.
03256bcMax Goldstein
libraries/List.elm+7
@@ -20,6 +20,9 @@ list must have the same type.
20
20
21# Special Folds
21# Special Folds
22@docs sum, product, maximum, minimum, all, any, and, or
22@docs sum, product, maximum, minimum, all, any, and, or
23+
24+# Sorting
25+@docs sort
23-}
26-}
24
27
25import open Basics
28import open Basics
@@ -224,3 +227,7 @@ drop = Native.List.drop
224-}
227-}
225repeat : Int -> a -> [a]
228repeat : Int -> a -> [a]
226repeat = Native.List.repeat
229repeat = Native.List.repeat
230+
231+{-| Sort a list in ascending order. -}
232+sort : [comparable] -> [comparable]
233+sort = Native.List.sort
libraries/Native/List.js+2−2
@@ -214,8 +214,8 @@ Elm.Native.List.make = function(elm) {
214
214
215 function sort(xs) {
215 function sort(xs) {
216 function cmp(a,b) {
216 function cmp(a,b) {
217− var ord = Utils.compare(a,b).ctor;
217+ var ord = Utils.compare(a)(b).ctor;
218− return ord=== 'EQ' ? 0 : ord === 'LT' ? -1 : 1;
218+ return ord === 'EQ' ? 0 : ord === 'LT' ? -1 : 1;
219 }
219 }
220 return fromArray(toArray(xs).sort(cmp));
220 return fromArray(toArray(xs).sort(cmp));
221 }
221 }