From 942893594dacf121c3d43256c15dd7fd753a5d14 Mon Sep 17 00:00:00 2001 From: Tuna Date: Sat, 10 Nov 2018 10:15:43 +0700 Subject: [PATCH] refactor RemoveItemFromArray --- common/types.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/common/types.go b/common/types.go index 54658709ac..95ea6bc17b 100644 --- a/common/types.go +++ b/common/types.go @@ -246,24 +246,18 @@ func (a UnprefixedAddress) MarshalText() ([]byte, error) { // Extract validators from byte array. func RemoveItemFromArray(array []Address, items []Address) []Address { - if items == nil { + if len(items) == 0 { return array } - i := 0; - for i < len(array) { - value := array[i] - remove := false - for _, item := range items { - if value == item { + + for _, item := range items { + for i := len(array) - 1; i >= 0; i-- { + if array[i] == item { array = append(array[:i], array[i+1:]...) - remove = true - break } } - if !remove { - i++ - } } + return array }