pelican/internal/board/shuffle.go

27 lines
679 B
Go
Raw Permalink Normal View History

package board
// shuffle takes a list of Statuses and swaps its position with the Status closer to its desired
// position until it reaches it.
//
// This is currently used to move specified columns forwards or backwards on the Kanban board.
// When a column changes position the other columns shuffle forward or backwards as required.
func shuffle(list []Status, oldIndex, newIndex int) []Status {
if newIndex == oldIndex {
return list
}
if newIndex < oldIndex {
for i := oldIndex; i > newIndex; i-- {
list[i], list[i-1] = list[i-1], list[i]
}
return list
}
for i := oldIndex; i < newIndex; i++ {
list[i], list[i+1] = list[i+1], list[i]
}
return list
}