Last active
November 21, 2018 11:07
-
-
Save edpichler/68c176b9de669366bccdb5baab2aaa29 to your computer and use it in GitHub Desktop.
Revisions
-
edpichler revised this gist
Nov 21, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,5 +20,5 @@ fun main(args: Array<String>) { val flatten = flatten(flatThis) println(flatten) // this prints [1, 2, 3, 4, 5, 6] } -
edpichler created this gist
Nov 21, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ fun flatten(numbers: Array<Any>): ArrayList<Int> { val flattenReturn = arrayListOf<Int>() numbers.forEach { it -> if (it is Int) { flattenReturn.add(it) } else { val temp = flatten(it as Array<Any>) flattenReturn.addAll(temp) } } return flattenReturn; } /** * Test the method. */ fun main(args: Array<String>) { val first: Array<Any> = arrayOf(1, 2, arrayOf(3, 4)) val flatThis : Array<Any> = arrayOf(first, 5, 6) val flatten = flatten(flatThis) println(flatten) }