Skip to content

Instantly share code, notes, and snippets.

@devrimbaris
Created April 4, 2015 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devrimbaris/18c25cef05aa8ece3def to your computer and use it in GitHub Desktop.
Save devrimbaris/18c25cef05aa8ece3def to your computer and use it in GitHub Desktop.
Javascript reduce example
<script>
var uyeler = [{
ad: "baris",
soyad: "acar",
g: "e"
}, {
ad: "esen",
soyad: "acar",
g: "k"
}, {
ad: "ege",
soyad: "acar",
g: "e"
}, {
ad: "mert",
soyad: "acar",
g: "e"
}];
$(document).ready(function() {
var x = uyeler.reduce(function(memo, uye) {
if (memo[uye.g] == null) memo[uye.g] = 0;
memo[uye.g] += 1;
return memo;
}, {});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment