aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Yoo2022-10-23 21:31:09 +0000
committerJames Yoo2022-10-23 21:31:09 +0000
commit52035dd7c9c0cca23c4df1a0dc178222bd9beb54 (patch)
tree892e56f94d8aa7973b6e336be0b6992f323de1af
parent3de00aa8511713c50564fa183671486530fdc0ae (diff)
Adding fib in Scala
-rw-r--r--entries/jyoo980/scala/Fib.scala6
1 files changed, 6 insertions, 0 deletions
diff --git a/entries/jyoo980/scala/Fib.scala b/entries/jyoo980/scala/Fib.scala
new file mode 100644
index 0000000..05bdd1e
--- /dev/null
+++ b/entries/jyoo980/scala/Fib.scala
@@ -0,0 +1,6 @@
+def fib(n: Int) =
+ (0 until n).foldLeft((0, 1)) {
+ case ((prev, curr), _) => (curr, prev + curr)
+ } match {
+ case (n, _) => n
+ }