Skip to content

Instantly share code, notes, and snippets.

@MansurAshraf
Created October 19, 2013 00:22
Show Gist options
  • Select an option

  • Save MansurAshraf/7050203 to your computer and use it in GitHub Desktop.

Select an option

Save MansurAshraf/7050203 to your computer and use it in GitHub Desktop.
word pair
object WordPair {
def main(args: Array[String]) = {
val line = "Android is a Linux-based operating system designed primarily for touchscreen mobile devices".split(" ").toList
val pairs = wordPair(line)
println(pairs)
}
def wordPair(line: List[String]): List[(String, String)] = line match {
case Nil => Nil
case x :: Nil => Nil
case x :: y :: tail => (x, y) :: wordPair(y :: tail)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment