I have an Array, or Seq looks like
val myArray = collection.mutable.ArrayBuffer[Int](1,4,8,10,12,13)
val newElem = 7
I want to insert the new element into the Array at the right position, so that the array is still ordered.
I don't want to generate a new array here.
My solution is to find the insert position first, and then insert it.
def findInsertPosition(myArray: collection.multable.ArrayBuffer[Int], newElem: Int): Int
then call
myArray.insert(pos, newElem)
The question is how to write the findInsertPosition function in Scala style, without using while, for loops?
or if you have better solution?