Last active
November 10, 2017 14:53
-
-
Save sozysozbot/1c45309c64b0d58fc7c6d9e80630dc34 to your computer and use it in GitHub Desktop.
This file contains 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 counting(arr){ | |
var obj={}; | |
for(var i=0;i<arr.length;i++){ | |
obj[arr[i][0]] = obj[arr[i][0]] ? (obj[arr[i][0]]+arr[i][1]) : arr[i][1]; | |
} | |
return obj; | |
} | |
var dat2 = dat.map(a=>a[1]).map(a => [].concat.apply([],a).map(b=>[b,1/a.length])) | |
var dat3 = [].concat.apply([],dat2); | |
console.log(JSON.stringify(counting(dat3))); |
This file contains 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 counting(arr){ | |
var obj={}; | |
for(var i=0;i<arr.length;i++){ | |
obj[arr[i]] = obj[arr[i]] ? (obj[arr[i]]+1) : 1; | |
} | |
return obj; | |
} | |
var dat2 = dat.map(a=>a[1]).filter(a=>a.length==1).map(a=>a[0]); | |
var dat3 = [].concat.apply([],dat2); | |
console.log(JSON.stringify(counting(dat3))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment