aboutsummaryrefslogtreecommitdiff
path: root/lib/ints/ints.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-03-02 06:26:35 +0700
committerShulhan <ms@kilabit.info>2019-03-02 06:26:35 +0700
commit4d522fa86a8ff2c4468c7e1adff5665c405bb07c (patch)
tree9e929a79d1bad3c4dbe9b4a5c63a8823cea081ba /lib/ints/ints.go
parent8a5dfcccd447a9e2693bace81525d6264abccc63 (diff)
downloadpakakeh.go-4d522fa86a8ff2c4468c7e1adff5665c405bb07c.tar.xz
ints: add function to remove value from slice
The Remove function remove value "v" from slice if its exist and return new slice and true; otherwise, if not found, return unmodified slice and false.
Diffstat (limited to 'lib/ints/ints.go')
-rw-r--r--lib/ints/ints.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/ints/ints.go b/lib/ints/ints.go
index 09a5cbf1..73b915dd 100644
--- a/lib/ints/ints.go
+++ b/lib/ints/ints.go
@@ -233,6 +233,20 @@ func MinRange(d []int, l, r int) (v, i int) {
}
//
+// Remove value "v" from slice if its exist and return new slice and true;
+// otherwise, if not found, return unmodified slice and false.
+//
+func Remove(d []int, v int) ([]int, bool) {
+ for x := 0; x < len(d); x++ {
+ if d[x] == v {
+ d = append(d[:x], d[x+1:]...)
+ return d, true
+ }
+ }
+ return d, false
+}
+
+//
// SortByIndex will sort the slice `d` using sorted index `sortedIds`.
//
func SortByIndex(d *[]int, sortedIds []int) {