Created
January 29, 2019 01:11
-
-
Save sholadedokun/acee436b2676f831b92f39a0b4abf97f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function filterLists(list){ | |
try{ | |
let filteredList=list.filter(function(item, index){ | |
return item.age >= 30 && item.age <= 40 | |
}); | |
let genderIndex=[] | |
let groupedList=filteredList.reduce(function(accum, item, index){ | |
let gIndex= genderIndex.indexOf(item.gender); | |
if(gIndex>=0){ | |
accum[gIndex].push(item); | |
return accum; | |
} | |
else{ | |
genderIndex.push(item.gender) | |
accum.push([item]); | |
return accum; | |
} | |
},[]); | |
return groupedList | |
} | |
catch(e){ | |
return "List must be an array of Object"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment