How do I sort the arrays in descending order in PureScript?
Currently, sort
and then reverse
like ↓.
module Main
(main
where
import Prelude
import Data.Array as Array
import Effect (Effect)
import Effect.Console as Console
main::Effect Unit
main=
let xs = [3,1,2,5,4]
in Console.logShow (Array.reverse (Array.sort xs))
Please let me know if there is a better way.
purescript
You can also use compare
+ flip
+ sortBy
.
Array.sortBy(flip compare)xs
© 2024 OneMinuteCode. All rights reserved.