-
Notifications
You must be signed in to change notification settings - Fork 0
/
Meeting.kt
41 lines (34 loc) · 1.2 KB
/
Meeting.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.smlnskgmail.jaman.codewarskotlin.kyu6
// https://www.codewars.com/kata/59df2f8f08c6cec835000012
class Meeting(private val input: String) {
fun solution(): String {
val meetingUnits = mutableListOf<MeetingUnit>()
input.split(";").forEach {
val separatorIndex = it.indexOf(":")
meetingUnits.add(
MeetingUnit(
it.substring(0, separatorIndex).toUpperCase(),
it.substring(separatorIndex + 1, it.length).toUpperCase()
)
)
}
return meetingUnits
.sortedByDescending { it }
.joinToString("") { it.toString() }
}
class MeetingUnit(
private val name: String,
private val lastName: String
) : Comparable<MeetingUnit> {
override fun compareTo(other: MeetingUnit): Int {
return if (other.lastName != lastName) {
other.lastName.compareTo(lastName, true)
} else {
other.name.compareTo(name, true)
}
}
override fun toString(): String {
return "(${lastName}, ${name})"
}
}
}