Last active
August 29, 2015 13:58
-
-
Save ajozwik/9937483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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