Advertisement
Guest User

Untitled

a guest
Mar 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.36 KB | None | 0 0
  1. import scala.collection.{GenSeq, SeqLike}
  2. import scala.math._
  3. def minByFeature[A:Ordering,B](seq:GenSeq[B], feature:Function1[B,A]):B = {
  4.   val featureseq = seq.map(feature)
  5.   val minFeature = featureseq.min
  6.   val minFeatureIndex = featureseq.indexOf(minFeature)
  7.   seq(minFeatureIndex)
  8. }
  9.  
  10. val l = List(-2,-3,-3,-4,-5)
  11.  
  12. minByFeature[Int,Int](l,(x=>abs(x)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement