Problem 22
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package ninetyNineScalaProblems
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
object Problem22:
|
||||
def range(start: Int, stop: Int): List[Any] =
|
||||
@tailrec
|
||||
def loop(cursor: Int, acc: List[Any]): List[Any] =
|
||||
cursor match
|
||||
case c if c <= stop =>
|
||||
loop(cursor + 1, cursor :: acc)
|
||||
case c if c > stop =>
|
||||
acc
|
||||
loop(start, List()).reverse
|
||||
Reference in New Issue
Block a user