This is a simple exercise I am solving in Scala: given a list l
return a new list, which contains every n-th
element of l
. If n > l.size
return an empty list.
def skip(l: List[Int], n: Int) =
Range(1, l.size/n + 1).map(i => l.take(i * n).last).toList
My solution (see above) seem to work but I am looking for smth. simpler. How would you simplify it?