mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
commit
970f9b3981
@ -778,24 +778,30 @@
|
|||||||
a)
|
a)
|
||||||
|
|
||||||
(defn sort
|
(defn sort
|
||||||
"Sort an array in-place. Uses quick-sort and is not a stable sort."
|
``Sort `ind` in-place, and return it. Uses quick-sort and is not a stable sort.
|
||||||
[a &opt before?]
|
|
||||||
(sort-help a 0 (- (length a) 1) (or before? <)))
|
If a `before?` comparator function is provided, sorts elements using that,
|
||||||
|
otherwise uses `<`.``
|
||||||
|
[ind &opt before?]
|
||||||
|
(sort-help ind 0 (- (length ind) 1) (or before? <)))
|
||||||
|
|
||||||
(defn sort-by
|
(defn sort-by
|
||||||
``Returns `ind` sorted by calling
|
``Returns `ind` sorted by calling
|
||||||
a function `f` on each element and comparing the result with <.``
|
a function `f` on each element and comparing the result with `<`.``
|
||||||
[f ind]
|
[f ind]
|
||||||
(sort ind (fn [x y] (< (f x) (f y)))))
|
(sort ind (fn [x y] (< (f x) (f y)))))
|
||||||
|
|
||||||
(defn sorted
|
(defn sorted
|
||||||
"Returns a new sorted array without modifying the old one."
|
``Returns a new sorted array without modifying the old one.
|
||||||
|
|
||||||
|
If a `before?` comparator function is provided, sorts elements using that,
|
||||||
|
otherwise uses `<`.``
|
||||||
[ind &opt before?]
|
[ind &opt before?]
|
||||||
(sort (array/slice ind) before?))
|
(sort (array/slice ind) before?))
|
||||||
|
|
||||||
(defn sorted-by
|
(defn sorted-by
|
||||||
``Returns a new sorted array that compares elements by invoking
|
``Returns a new sorted array that compares elements by invoking
|
||||||
a function `f` on each element and comparing the result with <.``
|
a function `f` on each element and comparing the result with `<`.``
|
||||||
[f ind]
|
[f ind]
|
||||||
(sorted ind (fn [x y] (< (f x) (f y)))))
|
(sorted ind (fn [x y] (< (f x) (f y)))))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user