JSFiddle - React, Tailwind, and code Playground

JavaScript

a = ['foo', 'foo', 'bar'];

var b = _.reduce(a,function(counts,key){ counts[key]++; return counts },
                 _.object( _.map( _.uniq(a), function(key) { return [key, 0] })))

alert(b)