Skip to content

Instantly share code, notes, and snippets.

@greister
Created February 10, 2017 11:37
Show Gist options
  • Save greister/b9fafb8c46e88573b5b45df1b51276ee to your computer and use it in GitHub Desktop.
Save greister/b9fafb8c46e88573b5b45df1b51276ee to your computer and use it in GitHub Desktop.
List repeats
def f(num:Int,arr:List[Int]):List[Int] = {
if (!arr.isEmpty)
for ( i <- 1 to num) println(arr.head)
f(num, arr.tail)
}
def f(num:Int,arr:List[Int]):List[Int] = arr.flatMap(List.fill(num)(_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment