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

Share

Need a budget?

Let's talk
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget