Created
September 24, 2018 14:11
-
-
Save vascoV/238e32aecb7739be80d386661afbccb5 to your computer and use it in GitHub Desktop.
A function to flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun flattenedArray(array: Array<Array<Int>>): List<Int> { | |
return array.flatten() | |
} | |
fun main(args: Array<String>) { | |
println(flattenedArray(arrayOf(arrayOf(1), arrayOf(2, 3), arrayOf(4, 5), arrayOf(6, 7, 8))) | |
//Output: [1, 2, 3, 4, 5, 6, 7, 8] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment