Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const groups = [
- {
- name : 'Publíco Geral',
- type : 'completo'
- },
- {
- name : 'Publíco Geral',
- type : 'parcial'
- },
- {
- name : 'Maior de 60 anos',
- type : 'completo'
- },
- {
- name : 'Maior de 60 anos',
- type : 'parcial'
- },
- ];
- const count = groups.reduce((result, item) => {
- let group = result.find(group => group.name === item.name && group.type === item.type);
- if(group){
- group.count = group.count++;
- }else(group){
- group = {
- name : item.name,
- type : item.type,
- count : 1
- }
- result.push(group);
- }
- });
- console.log(count);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement