14 lines
286 B
Go
14 lines
286 B
Go
package array
|
|
|
|
func Filter[T any](array []T, callback func(T, int, []T) bool) []T {
|
|
filteredArray := make([]T, 0, len(array))
|
|
|
|
for index, element := range array {
|
|
if callback(element, index, array) {
|
|
filteredArray = append(filteredArray, element)
|
|
}
|
|
}
|
|
|
|
return filteredArray
|
|
}
|