Skip to content

Instantly share code, notes, and snippets.

@wiyoe
Created January 23, 2018 07:30
Show Gist options
  • Select an option

  • Save wiyoe/fe6a25ac3db960462ca46124c6d07ed2 to your computer and use it in GitHub Desktop.

Select an option

Save wiyoe/fe6a25ac3db960462ca46124c6d07ed2 to your computer and use it in GitHub Desktop.
Loadash groupBy Count
var dd = [
{"classroom_fk":9,"classroom_name":"9. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":10,"classroom_name":"10. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":11,"classroom_name":"11. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":11,"classroom_name":"11. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":11,"classroom_name":"11. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":12,"classroom_name":"12. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":12,"classroom_name":"12. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":12,"classroom_name":"12. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":10,"classroom_name":"10. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true},
{"classroom_fk":9,"classroom_name":"9. Sınıf","maxLicenceNumber":100,"licenceCount":6,"pointtype_related":true}
]
var result = _(dd)
.groupBy('classroom_fk')
.map(function(items, classroom_fk) {
return { classroom_fk: classroom_fk, count: items.length };
}).value();
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment