Skip to content

Instantly share code, notes, and snippets.

@rktoomey
Last active December 24, 2015 14:39
Show Gist options
  • Select an option

  • Save rktoomey/6814276 to your computer and use it in GitHub Desktop.

Select an option

Save rktoomey/6814276 to your computer and use it in GitHub Desktop.
scala> val l = List(2d, 1d, 4d, Double.NaN, 4d, Double.NaN, -99d, 666d)
l: List[Double] = List(2.0, 1.0, 4.0, NaN, 4.0, NaN, -99.0, 666.0)
scala> l.max
res0: Double = 666.0
scala> l.min
res1: Double = -99.0
scala> l.sorted
res2: List[Double] = List(-99.0, 1.0, 2.0, 4.0, 4.0, 666.0, NaN, NaN)
scala> l.sortWith((a,b)=>a>b)
res3: List[Double] = List(666.0, 4.0, 4.0, 2.0, 1.0, NaN, NaN, -99.0)
scala> l.sortWith((a,b)=>a<b)
res4: List[Double] = List(1.0, 2.0, 4.0, NaN, 4.0, NaN, -99.0, 666.0)
scala> val l = List(2d, 1d, 4d, Double.NaN, 4d, Double.NaN, -99d, 666d, Double.NaN)
l: List[Double] = List(2.0, 1.0, 4.0, NaN, 4.0, NaN, -99.0, 666.0, NaN)
scala> l.max
res5: Double = NaN
scala> l.min
res6: Double = NaN
scala> l.sorted
res7: List[Double] = List(-99.0, 1.0, 2.0, 4.0, 4.0, 666.0, NaN, NaN, NaN)
scala> l.sortWith((a,b)=>a>b)
res8: List[Double] = List(666.0, 4.0, 4.0, 2.0, 1.0, NaN, NaN, -99.0, NaN)
scala> l.sortWith((a,b)=>a<b)
res9: List[Double] = List(1.0, 2.0, 4.0, NaN, 4.0, NaN, -99.0, 666.0, NaN)
@rktoomey

rktoomey commented Oct 3, 2013

Copy link
Copy Markdown
Author

Scala 2.10.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment