Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created June 29, 2013 20:55
Show Gist options
  • Save gclaramunt/5892633 to your computer and use it in GitHub Desktop.
Save gclaramunt/5892633 to your computer and use it in GitHub Desktop.
Sort a list of ips in Scala
List("129.95.30.40","5.24.69.2","19.20.203.5","1.2.3.4","19.20.21.22","5.220.100.50").
map(_.split('.').map(_.toInt)).
map( { case Array(x1,x2,x3,x4) => (x1,x2,x3,x3) } ).sorted.
map { case (x1,x2,x3,x4) => "%s.%s.%s.%s".format(x1,x2,x3,x4)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment