I tried to use `(0 until list.size - 1). filter{ ...
# getting-started
t
I tried to use
(0 until list.size - 1). filter{ list[it] == list[it + 1] }
but it doesn't work for case
333
->
33
Do I not undestand smthng?
p
@timurnav
Copy code
list.filterIndexed { i, x -> i == 0
        || x != list[i - 1]
        || (i + 1 < list.size && x == list[i + 1]) }
😄
ah, its about pair… I thought you need to remove one from each sequence, i.e
1111
->
111
seems it is not possible without a loop
Copy code
val newList = arrayListOf<Int>()
var i = 0
while (i < list.size) {
    newList.add(list[i++])
    if (i < list.size && list[i - 1] == list[i]) i++
}