You are viewing a single comment's thread. Return to all comments →
Scala, such that I am new to Scala and functional programming
def getNumElements(s: Int, element: Int, result: List[Int]): List[Int] = { if (s > 0) { getNumElements(s - 1, element, result :+ element) } else { result } } def f(num: Int, arr: List[Int], result: List[Int] = List(), repeater: (Int, Int, List[Int]) => List[Int] = getNumElements ): List[Int] = { if (arr.size > 0) { f(num, arr.tail, result ::: repeater(num, arr.head, List())) } else { result } }
Seems like cookies are disabled on this browser, please enable them to open this website
List Replication
You are viewing a single comment's thread. Return to all comments →
Scala, such that I am new to Scala and functional programming