forked from exercism/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Atbash - use object instead of an instance - refs exercism#242. Add A…
…tbash.scala - refs exercism#137. Add topics to config.json - refs exercism#125
- Loading branch information
Showing
4 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
case class Atbash() { | ||
def encode(s: String): String = | ||
s.foldLeft("")((acc, c) => acc + substitute(c)).grouped(5).mkString(" ") | ||
|
||
object Atbash { | ||
private def substitute(c: Char) = | ||
if (c.isDigit) c.toString | ||
else if (c.isLetter) ('a' + ('z' - c.toLower)).toChar.toString | ||
else "" | ||
|
||
def encode(s: String): String = | ||
s.foldLeft("")((acc, c) => acc + substitute(c)).grouped(5).mkString(" ") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Atbash { | ||
def encode(s: String): String = ??? | ||
} |
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