Skip to content

Instantly share code, notes, and snippets.

@sachinKumarGautam
Created May 17, 2018 14:41
Show Gist options
  • Save sachinKumarGautam/31d5c893c236382b429342d8452ac3b8 to your computer and use it in GitHub Desktop.
Save sachinKumarGautam/31d5c893c236382b429342d8452ac3b8 to your computer and use it in GitHub Desktop.
var mammals = [
{
name: 'bantu',
behaviour: [2,3,4]
},
{
name: 'mantu',
behaviour: [2,3,4]
},
{
name: 'chantu',
behaviour: [2,3,5]
}
]
function getFilteredArray(mammals, searchString) {
return mammals.filter(function(mammal) {
return mammal.behaviour.indexOf(searchString) > -1 ? 1 : 0
})
}
console.log(getFilteredArray(mammals, 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment