From 52035dd7c9c0cca23c4df1a0dc178222bd9beb54 Mon Sep 17 00:00:00 2001 From: James Yoo Date: Sun, 23 Oct 2022 14:31:09 -0700 Subject: Adding fib in Scala --- entries/jyoo980/scala/Fib.scala | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 entries/jyoo980/scala/Fib.scala (limited to 'entries/jyoo980/scala') 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 + } -- cgit v1.2.3-70-g09d2