mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-26 07:13:36 +01:00
22 lines
731 B
Go
22 lines
731 B
Go
package array
|
|
|
|
// RemoveElements returns a new slice containing all elements from `allElements` that are not in `elementsToRemove`
|
|
func RemoveElements(allElements, elementsToRemove []string) []string {
|
|
// Create a map to store elements to remove for quick lookup
|
|
removeMap := make(map[string]struct{}, len(elementsToRemove))
|
|
for _, elem := range elementsToRemove {
|
|
removeMap[elem] = struct{}{}
|
|
}
|
|
|
|
// Create a slice to store the result
|
|
result := make([]string, 0, len(allElements)) // Preallocate memory based on the size of allElements
|
|
for _, elem := range allElements {
|
|
// Check if the element is not in the removeMap
|
|
if _, found := removeMap[elem]; !found {
|
|
result = append(result, elem)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|