Skip to content

Instantly share code, notes, and snippets.

@weidagang
Created July 1, 2014 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weidagang/367791a978e9067cb748 to your computer and use it in GitHub Desktop.
Save weidagang/367791a978e9067cb748 to your computer and use it in GitHub Desktop.
HackerRank: Sum of Odd Numbers
package sum.odd
object Main {
def f(arr: List[Int]): Int = arr.map(x => (if (0 == x % 2) 0 else x)).reduce((x, y) => x + y)
def main(args: Array[String]) {
val r = f(List(2, 3, 4, 5, -7));
println(r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment