If you mixed Intand Array[Int], which is not very good for a start, you can do something like
in.flatMap{ case i: Int => Array(i); case ai: Array[Int] => ai }
(it throws an exception if you put something else in your array). So you can use this as the basis for a recursive function:
def flatInt(in: Array[Any]): Array[Int] = in.flatMap{
case i: Int => Array(i)
case ai: Array[Int] => ai
case x: Array[_] => flatInt(x.toArray[Any])
}
If you do not know what you have in your nested arrays, you can replace the above Intwith Anyand get a flat one Array[Any]as a result. (Edit: The case Anymust be the last.)
(: , , .)