Chains several array functions
filter
,
map
together.
Uses
onlyMen
and
underTwenty
methods for filtering the result.
Uses
onlyNames
function to take only names from the objects.
let people = [
{name: 'გიორგი', age: 15, gender: 'male'},
{name: 'ეკატერინე', age: 35, gender: 'female'},
{name: 'დავითი', age: 75, gender: 'male'},
{name: 'ნინო', age: 18, gender: 'female'},
{name: 'თორნიკე', age: 11, gender: 'male'}
]
function onlyMen(human) {
return human.gender == 'male'
}
function underTwenty(human) {
return human.age < 20
}
function onlyNames(human) {
return human.name
}
let onlyBoysNames = people.filter(onlyMen).filter(underTwenty).map(onlyNames)
document.write(onlyBoysNames)