Here's a link to the Codewars Kata: https://www.codewars.com/kata/57ee4a67108d3fd9eb0000e7/javascript
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!
If you liked this article please follow me on Dev.to for my latest articles. I'm tweeting my journey on Twitter daily, this way to my LinkedIn, and this is my Youtube channel :)
I share my knowledge on,
- 🌐 Web Development
- ✍️ Content Creation
- 💼 Career Development
- 🦾Personal Growth
- And more!