summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-04-03 22:05:32 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-10 18:03:21 +0100
commitf885b79568a221f9d1cf8edc612f69bec5aad1cc (patch)
treea41f0e5bded6f5081015836ed5f9be2d323907fd
parent747d8bca01440a4274033627cc235274c3af308f (diff)
downloadcoursera-f885b79568a221f9d1cf8edc612f69bec5aad1cc.zip
coursera-f885b79568a221f9d1cf8edc612f69bec5aad1cc.tar.gz
Scala : add sandbox/sum
-rw-r--r--Scala/sandbox/sum.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/Scala/sandbox/sum.scala b/Scala/sandbox/sum.scala
new file mode 100644
index 0000000..a09f26b
--- /dev/null
+++ b/Scala/sandbox/sum.scala
@@ -0,0 +1,14 @@
+
+object Sum {
+
+ def sum (f: Int => Int, a: Int, b: Int) = {
+ def loop(a: Int, acc: Int): Int =
+ if (a > b) acc
+ else loop(a + 1, f(a) + acc)
+ loop(a, 0)
+ }
+
+ def run =
+ println(sum(x => x * x, 3, 5))
+
+}