bj0
12/04/2017, 8:46 PMremoveAt
implies passing an index though ?karelpeeters
12/04/2017, 8:47 PMlist.withoutElementAt(index)
.stephan_marshay
12/04/2017, 8:50 PMkarelpeeters
12/04/2017, 8:50 PManswers[index]
isn't guaranteed to be the first occurrence of that value.karelpeeters
12/04/2017, 8:51 PMcedric
12/04/2017, 8:53 PMremoveAt
should be (almost) constant time while -
is linearPavlo Liapota
12/05/2017, 10:52 AMPavlo Liapota
12/05/2017, 10:53 AMMutableList
instead.Pavlo Liapota
12/05/2017, 10:53 AMPavlo Liapota
12/05/2017, 10:54 AMfun <T> List<T>.withoutElementAt(index: Int): List<T>
= this.toMutableList().apply { removeAt(index) }
Pavlo Liapota
12/05/2017, 10:54 AMfun <T> List<T>.withoutElementAt1(index: Int)
= this.asSequence()
.withIndex()
.filter { it.index != index}
.map { it.value }
.toList()
Pavlo Liapota
12/05/2017, 10:54 AMfun <T> List<T>.withoutElementAt2(index: Int): List<T> {
val result = mutableListOf<T>()
for (i in this.indices) {
if (i != index) result.add(this[i])
}
return result
}
Pavlo Liapota
12/05/2017, 10:58 AMPavlo Liapota
12/05/2017, 11:00 AMkarelpeeters
12/05/2017, 11:01 AMcedric
12/05/2017, 5:19 PMList
representation that I described in the follow up conversation