Created
July 14, 2018 04:44
-
-
Save JakeTheCorn/cae1983b6efe93904af097fe1801a02e to your computer and use it in GitHub Desktop.
Remove Item from Slice in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cg *ColorGroup) removeColor(colorToRemove string) (int, error) { | |
colorRemoved := false | |
for i, c := range cg.Colors { | |
if colorToRemove == c { | |
cg.Colors = append(cg.Colors[:i], cg.Colors[i+1:]...) | |
colorRemoved = true | |
} | |
} | |
if colorRemoved { | |
return 0, nil | |
} | |
return -1, errors.New("Could Not Find Color to Remove") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment