Skip to content

Instantly share code, notes, and snippets.

@jacekkolodziejski
Last active December 25, 2015 17:19
Show Gist options
  • Save jacekkolodziejski/7012173 to your computer and use it in GitHub Desktop.
Save jacekkolodziejski/7012173 to your computer and use it in GitHub Desktop.
object S99_P16 {
def drop[T](n: Int, ts: Seq[T]): Seq[T] = {
var iter = 0;
def op(el: T): Boolean = { iter = iter + 1; (iter % n != 0) }
ts filter op
}
def drop[T](n: Int, ts: Seq[T]): Seq[T] =
for (e <- ts.zipWithIndex if (e._2 + 1) % n != 0) yield e._1
def drop[T](n: Int, ts: Seq[T]): Seq[T] = {
def everyN(e: (T, Int)): Boolean = ((e._2 + 1) % n) != 0
ts.zipWithIndex.filter(everyN).map(_._1)
}
def drop[T](n: Int, ts: Seq[T]): Seq[T] =
ts.grouped(n).flatMap(_.take(n - 1)).toList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment