Skip to content

Instantly share code, notes, and snippets.

@soulduse
Last active January 13, 2018 09:18
Show Gist options
  • Save soulduse/05f149d24688c687d884018d3b60771e to your computer and use it in GitHub Desktop.
Save soulduse/05f149d24688c687d884018d3b60771e to your computer and use it in GitHub Desktop.
Getting longest one in array - Kotlin
val items = arrayOf(
longArrayOf(200, 0),
longArrayOf(95, 5, 95, 5),
longArrayOf(60, 7, 60, 7, 60, 7),
longArrayOf(43, 7, 43, 7, 43, 7, 43, 7),
longArrayOf(32, 8, 32, 8, 32, 8, 32, 8, 32, 8),
longArrayOf(25, 8, 25, 8, 25, 8, 25, 8, 25, 8, 25, 8),
longArrayOf(20, 9, 20, 9, 20, 9, 20, 9, 20, 9, 20, 9, 20, 9),
longArrayOf(16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9),
longArrayOf(13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9),
longArrayOf(9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11), // <-- Getting this itme
longArrayOf(9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13, 9, 13),
longArrayOf(9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16),
longArrayOf(9, 20, 9, 20, 9, 20, 9, 20, 9, 20, 9, 20, 9, 20),
longArrayOf(8, 25, 8, 25, 8, 25, 8, 25, 8, 25, 8, 25),
longArrayOf(8, 32, 8, 32, 8, 32, 8, 32, 8, 32),
longArrayOf(7, 43, 7, 43, 7, 43, 7, 43),
longArrayOf(7, 60, 7, 60, 7, 60),
longArrayOf(5, 90, 5, 90),
longArrayOf(0, 200)
)
val longestItem = items.sortedBy { it.size }.reversed().first()
// longestItem --> longArrayOf(9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment