Skip to content

Commit e9d131a

Browse files
committed
problem fibonacci solved in scala
1 parent 32fa90f commit e9d131a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

solutions/scala/Fibonacci.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Fibonacci {
2+
// accept a pos, starting with 1
3+
def apply(pos: Int) = {
4+
if (pos < 0) throw new IllegalArgumentException
5+
(1 until pos).foldLeft((0, 1))((t, _) => (t._2, t._1 + t._2))._1
6+
}
7+
}

0 commit comments

Comments
 (0)