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 From 9d6f7b9b5123c6e6d8d5a13ee3f4b5f63a0cf663 Mon Sep 17 00:00:00 2001 From: James Yoo Date: Sun, 23 Oct 2022 14:36:19 -0700 Subject: Adding return type to fib function --- entries/jyoo980/scala/Fib.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entries/jyoo980/scala') diff --git a/entries/jyoo980/scala/Fib.scala b/entries/jyoo980/scala/Fib.scala index 05bdd1e..f9107b0 100644 --- a/entries/jyoo980/scala/Fib.scala +++ b/entries/jyoo980/scala/Fib.scala @@ -1,4 +1,4 @@ -def fib(n: Int) = +def fib(n: Int): Int = (0 until n).foldLeft((0, 1)) { case ((prev, curr), _) => (curr, prev + curr) } match { -- cgit v1.2.3-70-g09d2