i want write algorithm matches list 2 values in scala.
for example, if have following list:
val list = list(1, 3, 6, 8, 9, 14, 18)
and have 2 values:
val = 4 val b = 14
i want list:
val result = list(6, 8, 9, 14)
if thinking using intersect
method of scala, works 2 lists.
i thought using cycle, not functional.
so ended no idea on how solve problem.
can me?
oh, can use intersect
, so:
scala> list(1, 3, 6, 8, 9, 14, 18) intersect (4 14) res1: list[int] = list(6, 8, 9, 14)
and can reverse order, resulting collection type different.
scala> 4 14 intersect list(1, 3, 6, 8, 9, 14, 18) res2: scala.collection.immutable.indexedseq[int] = vector(6, 8, 9, 14)
takeaway: scala has lots of different collection types, many of them play together.