Problem 28
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package ninetyNineScalaProblems
|
||||||
|
|
||||||
|
import scala.annotation.tailrec
|
||||||
|
|
||||||
|
object Problem28:
|
||||||
|
def lsort(list: List[List[Any]]): List[Any] =
|
||||||
|
list.sortWith((a, b) => a.length < b.length)
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package ninetyNineScalaProblems
|
||||||
|
|
||||||
|
class Problem26Suite extends munit.FunSuite:
|
||||||
|
List(
|
||||||
|
(List(List(1, 2), List(1, 2, 3, 4), List(1, 2, 3)), List(List(1, 2), List(1, 2, 3), List(1, 2, 3, 4))),
|
||||||
|
(List(List(1, 2), List(1, 2, 3), List(1, 2, 3, 4)), List(List(1, 2), List(1, 2, 3), List(1, 2, 3, 4))),
|
||||||
|
(List(), List()),
|
||||||
|
(List(List(1)), List(List(1))),
|
||||||
|
(List(List(1), List(1)), List(List(1), List(1))),
|
||||||
|
(List(List(1, 2, 3), List(4, 5), List(6, 7, 8), List(4, 5), List(9, 10, 11, 12), List(13, 14), List(15)),
|
||||||
|
List(List(15), List(4, 5), List(4, 5), List(13, 14), List(1, 2, 3), List(6, 7, 8), List(9, 10, 11, 12))),
|
||||||
|
).foreach:
|
||||||
|
case (list, expected) =>
|
||||||
|
test(s"lsort returns [$expected]"):
|
||||||
|
assertEquals(Problem28.lsort(list), expected)
|
||||||
Reference in New Issue
Block a user