Consider the following Scala Array x definition
scala> val x = Array(10, 32, 45, 54, 44, 37)
x: Array[Int] = Array(10, 32, 45, 54, 44, 37)
and an index selector, which is provided, and is guaranteed not to include out of bounds index values:
scala> val selector = Seq(0, 3, 5)
selector: Seq[Int] = List(0, 3, 5)
In Scala, what is a concise way to use selector in combination with x to select only those indices of x which match the desired indices in selector to produce a new result Array? Specifically, result is expected as:
result: Array(10, 54, 37)
Any help is appreciated. Thank you.