← Back to Gists

Sort array descending

📝 Rust
julia
julia · Level 1 ·

This Rust code snippet sorts an array in descending order using the sortby method with a comparison closure.

Rust
fn main() { let mut arr = [3, 1, 4, 1, 5, 9, 2, 6, 5]; arr.sortby(|a, b| b.cmp(a)); println!("{:?}", arr);
}

Comments

No comments yet. Start the discussion.