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
/** | |
* Takes a camel cased identifier name and returns an underscore separated | |
* name | |
* | |
* Example: | |
* camelToUnderscores("thisIsA1Test") == "this_is_a_1_test" | |
*/ | |
def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m => | |
"_" + m.group(0).toLowerCase() | |
}) |
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
//If we have a list with at least two elements sum them and add them to the rest of the list | |
//else return the head of the list | |
@tailrec | |
def sum(xs: List[Int]): Int = xs match { | |
case h :: i :: rest => sum(h + i :: rest) //we have a list with at least two elements | |
case _ => xs.head | |
} | |
//If we have a list with at least two elements, remove the smallest and recurse | |
//else return the head of the list/We have |