Created
May 17, 2018 14:41
-
-
Save sachinKumarGautam/31d5c893c236382b429342d8452ac3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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