Skip to content

Instantly share code, notes, and snippets.

@ajozwik
Last active August 29, 2015 13:58
Show Gist options
  • Save ajozwik/9937483 to your computer and use it in GitHub Desktop.
Save ajozwik/9937483 to your computer and use it in GitHub Desktop.
object S99_P14 {
def duplicate[T](as: Seq[T]): Seq[T] = as.flatMap(el => Seq.fill(2)(el))
}
object S99_P14 {
def duplicate[T](as: Seq[T]): Seq[T] = {
val reversed = as.foldLeft[Seq[T]](Nil) {
(acc, el) => el +: (el +: acc)
}
reversed.reverse
}
}
object S99_P14 {
def duplicate[T](as: Seq[T]): Seq[T] = {
val reversed = as.foldLeft[Seq[T]](Nil) {
(acc, el) => Seq.fill(2)(el) ++ acc
}
reversed.reverse
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment