/** * Some things to do with slices * @author ggtowell * created: July 22, 2021 **/ package main import "fmt" /** * Remove an element * You need to actually return the slice because after compression * The memory could get reallocated * Note that this version keeps the order of the items in the * original slice * @param sl the slice * @param loc the item to be removed * @return the smaller slice **/ func remove(sl []int, loc int) []int { if loc >= len(sl) || loc < 0 { return sl } copy(sl[loc:], sl[loc+1:]) return sl[:len(sl)-1] } func removeValue(sl []int, val int) []int { loc:=0 for ; loc