Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created February 10, 2013 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/4750562 to your computer and use it in GitHub Desktop.
Save chris-martin/4750562 to your computer and use it in GitHub Desktop.
import Ordering.Implicits._
val unsorted = "1.2.3|1.2.0|1.|1.3|1.24|.2|.1.5|.15|.1|2|2.1|3" split '|'
def parseInt(x: String): Int = x match { case "" => 0; case y: String => y.toInt }
unsorted.sortBy(_.split('.').map(parseInt).toSeq)
// Array(.1, .1.5, .2, .15, 1., 1.2.0, 1.2.3, 1.3, 1.24, 2, 2.1, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment