Filter out the geese (Codewars - 8kyu)

Filter out the geese (Codewars - 8kyu)

Here's a link to the Codewars Kata: codewars.com/kata/57ee4a67108d3fd9eb0000e7/..

The goal of this exercise is to get back an array without some specific elements in it (elements that are specified in the geese array).

Start the function

Here we'll create a function called gooseFilter that accepts a parameter named birds of type Array.

function gooseFilter(birds) {
//function body
}

Return the string with methods applied to it

return str

We start with a return statement because we already want the result of the function right off the bat.

Filter the array

.filter()

We use the filter method to get a subset of the original array (birds) based on specific criteria. The filter method tests each element of the array, so in our case here, we want to pull out ONLY the items that are not included in the geese array.

.filter(item => !geese.includes(item))

Summary

The final function looks like this:

function gooseFilter(birds){
let geese =  ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]
return birds.filter(item=> !geese.includes(item))
}

I hope it helps you!