Skip to content

Instantly share code, notes, and snippets.

@kastoestoramadus
Created November 21, 2017 20:09
Show Gist options
  • Save kastoestoramadus/8d2143bdcb49fbb163fdd0f99a39fbc0 to your computer and use it in GitHub Desktop.
Save kastoestoramadus/8d2143bdcb49fbb163fdd0f99a39fbc0 to your computer and use it in GitHub Desktop.
second
val phones = List("91125426", "97 625 992", "911", "9761")
def isConsistent(pl: List[String]) = {
val sorted = pl.map(_.replaceAll(" ", "").replaceAll("-","")).sorted
sorted.tail.foldLeft((true, sorted.head)){
case (bPrev, str) =>
(bPrev._1 && !str.startsWith(bPrev._2), str)
}._1
}
isConsistent(phones)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment