Problem 16

This commit is contained in:
2026-03-19 15:39:32 +01:00
parent 1a2a78b747
commit 1e9c69cd76
2 changed files with 34 additions and 0 deletions
@@ -0,0 +1,17 @@
package ninetyNineScalaProblems
import scala.annotation.tailrec
object Problem16:
def dropEveryNthElement(n: Int, list: List[Any]): List[Any] =
@tailrec
def loop(cursor: List[Any], acc: List[Any], count: Int): List[Any] =
cursor match
case e :: tail if count == n =>
loop(tail, acc, 1)
case e :: tail =>
loop(tail, e :: acc, count + 1)
case Nil =>
acc
loop(list, List(), 1).reverse