user2238185
user2238185

Reputation:

Selecting the Minumum Sized List in a List of List

I have list of list of integers.

List(List(1, 1, 1, 1), List(2, 1, 1), List(2, 2))

I want to get the minimum sized list from that list which is List(2,2). What is the recommended way of doing this in Scala ?

Upvotes: 3

Views: 87

Answers (1)

om-nom-nom
om-nom-nom

Reputation: 62835

Almost duplicate of another question that was asked today:

val xs = List(List(1, 1, 1, 1), List(2, 1, 1), List(2, 2))

xs.minBy(list => list.length)
// res0: List[Int] = List(2, 2)

Upvotes: 3

Related Questions