Skip to content

Instantly share code, notes, and snippets.

@letusfly85
Created June 8, 2014 05:44
Show Gist options
  • Save letusfly85/7db6a24ce8314a7c520f to your computer and use it in GitHub Desktop.
Save letusfly85/7db6a24ce8314a7c520f to your computer and use it in GitHub Desktop.
object CheckSame {
def main(args: Array[String]) {
println(checkSame("abca", "bcaa"))
println(checkSame("abc", "bcaa"))
}
/**
* check the sameness of each words by sort
* refs: http://www.ne.jp/asahi/hishidama/home/tech/scala/sample/sort.html#h_scala
*
*/
def checkSame(str1: String, str2: String): Boolean = {
val sorted1 = str1.map(_.toChar).sortWith(_ < _)
val sorted2 = str2.map(_.toChar).sortWith(_ < _)
return (sorted1 == sorted2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment