Kata of the Day #15

Filter out the geese

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #15

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.

TypeScript


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']));

Go


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"}))
}

Python


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']))

PHP


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
ByCesar Kohl

Need some help?

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
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe