RosettaCodeData/Task/Order-two-numerical-lists/Julia/order-two-numerical-lists.julia
2018-06-22 20:57:24 +00:00

13 lines
473 B
Text

function islexless(a::AbstractArray{<:Real}, b::AbstractArray{<:Real})
for (x, y) in zip(a, b)
if x == y continue end
return x < y
end
return length(a) < length(b)
end
using Primes, Combinatorics
tests = [[1, 2, 3], primes(10), 0:2:6, [-Inf, 0.0, Inf], [π, e, φ, catalan], [2015, 5], [-sqrt(50.0), 50.0 ^ 2]]
println("List not sorted:\n - ", join(tests, "\n - "))
sort!(tests; lt=islexless)
println("List sorted:\n - ", join(tests, "\n - "))