hariprasadraja
10/1/2019 - 11:03 AM

go slice apply filter and create new slice

this snippet executes the filter function over the slice and returns a new slice

	newArr := arr[:0]
	for i := range arr {
		if ok, validValue := filterFn(arr[i]); ok {
			newArr = append(b, validValue)
		} else {

			// XXX: garbage collect the unwanted elements of the underlying array
			arr[i] = 0 // nil or the zero value of T
		}
	}