If have list of af string, how can filter so equal neighbors only appears one?
Example:
['0.1', '0.1', '0.2','0.3','0.3','0.1','0.2']
['0.1', '0.2','0.3','0.1','0.2']
['0.1', '0.1', '0.2','0.3','0.3','0.1','0.2'].unique()
['0.1', '0.2','0.3'] //what is not wanted
So if you want remove duplicated neighbors, you should get next item from current loop. i come up something like this:
def example = ['0.1', '0.1', '0.2','0.3','0.3','0.1','0.2']
def array = []
example.eachWithIndex { item, index ->
def next = index < example.size() - 1 ? example[ index + 1 ] : null
if(next != item) {
array.push(item)
}
}
println array