Last active
January 4, 2016 07:29
-
-
Save travisvalentine/8588450 to your computer and use it in GitHub Desktop.
One method, two languages
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
# RUBY METHOD | |
# ----------------------------------- | |
def sum_multiples(min, max) | |
n = (max - 1) / n | |
sum = n * (n+1) / 2 * min | |
end |
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
// SCALA METHOD | |
// ----------------------------------- | |
def sum_multiples(min: Int, max: Int) : Int = { | |
var n = (max - 1) / min | |
var sum = n * (n+1) / 2 * min | |
return sum | |
} | |
// this is one way to run the method above, passing in numbers as variables | |
sum_multiples(3, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The differences:
return sum
used. Ruby doesn't need those explicit return statments. Sometimes people might add the following to the Ruby method:Again, sometimes people explicitly return in Ruby but in Scala I believe it's required.