fork download
  1. object Main extends App {
  2. implicit class shinyInterviewDedup(private val sc: StringContext) {
  3. import scala.StringContext._
  4. def uq(args: Any*) = dedup(sc.standardInterpolator(treatEscapes, args))
  5. }
  6.  
  7. def dedup(s: String): String = {
  8. s.foldLeft(List[Char]()) {
  9. case (accum, chr) =>
  10. accum match {
  11. case Nil => chr :: Nil
  12. case all @ (`chr` :: rest) => all
  13. case seq => chr :: seq
  14. }
  15. }.reverse.mkString
  16. }
  17.  
  18. println(dedup("aabbcc"))
  19. println(dedup("hhhxxxxxhfgffhh"))
  20.  
  21. println(uq"aabbcc")
  22. println(uq"hhhxxxxxhfgffhh")
  23. }
Success #stdin #stdout 0.4s 382080KB
stdin
Standard input is empty
stdout
abc
hxhfgfh
abc
hxhfgfh