Guest User

Untitled

a guest
Oct 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. final case class Triple (posOdd: List[Int], posEven: List[Int], neg: List[Int])
  2.  
  3. def triple(xs: List[Int]): Triple =
  4. xs.foldLeft(Triple(Nil, Nil, Nil))(
  5. (acc, x) =>
  6. if (x < 0)
  7. acc.copy(neg = x::acc.neg)
  8. else if (x % 2 == 0)
  9. acc.copy(posEven = x::acc.posEven)
  10. else
  11. acc.copy(posOdd = x::acc.posOdd)
  12. )
  13.  
  14. triple(List(2, 0, -1 , 3, 5 , -2))
Add Comment
Please, Sign In to add comment