drop(List(1, 2, 3), 1) == List(2,3)
sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[+A](head: A, tail: List[A]) extends List[A]
def drop[A](l: List[A], n: Int): List[A] = if (n <= 0) l else l match { case Nil => Nil case Cons(_, t) => drop(t, n - 1) }
def drop[A](l: List[A], n: Int): List[A] = if (n == 0) l else l match { case Nil => Nil case Cons(_, t) => drop(t, n +1) }
def drop[A](l: List[A], n: Int): List[A] = if (n >= 0) l else l match { case Nil => Nil case Cons(_, t) => drop(t, n +1) }
Login in to like
Login in to comment
or Read more about Scala Quizzes
Login in to like
Login in to comment