Sorting Sequences

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create Two Vectors

// Create two vectors
val ages = Vector(23,42,12,34)
val lastName = Vector("Jackson", "Dillan", "Bower", "Stein")

Sort Alphabetically

// View the sequence alphabetically
Vector(Bower, Dillan, Jackson, Stein)

Sort Ascending

// View the sequence in ascending order
Vector(12, 23, 34, 42)

Sort Descending

// View the sequence sorted using i > j
ages.sortWith(_ > _)
Vector(42, 34, 23, 12)

Sort By Length

// Voew the sequence sorted by descending length
lastName.sortWith(_.length > _.length)
Vector(Jackson, Dillan, Bower, Stein)