Filter out the geese
Write a function that takes a list of strings as an argument and returns a filtered list containing the same elements but with the 'geese' removed.
function gooseFilter (birds: string[]): string[] {
const geese: string[] = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"];
return birds.filter(bird => ! geese.includes(bird));
}
console.log(gooseFilter(['African', 'Not Geese']));
package main
import "fmt"
func gooseFilter(birds []string) []string {
geese := []string{"African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"}
filteredBirds := make([]string, 0)
for _, bird := range birds {
if !contains(geese, bird) {
filteredBirds = append(filteredBirds, bird)
}
}
return filteredBirds
}
func contains(sl []string, name string) bool {
for _, value := range sl {
if value == name {
return true
}
}
return false
}
func main() {
fmt.Println(gooseFilter([]string{"African", "Not Geese"}))
}
def goose_filter(birds):
geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]
return [bird for bird in birds if bird not in geese]
print(goose_filter(['African', 'Not Geese']))
function goose_filter($birds) {
$geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"];
$filteredBirds = [];
foreach ($birds as $bird) {
if (!in_array($bird, $geese)) {
$filteredBirds[] = $bird;
}
}
return $filteredBirds;
}
print_r(goose_filter(['African', 'Not Geese']));
Go to Kata
Want us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.
Let's see