lodash/underscore查找数组中非唯一元素的数量

ras*_*adb 0 javascript arrays underscore.js lodash

我有一个包含一些字符串的数组,我需要找出有多少字符串不是唯一的 - 与_.uniq相反.我已经尝试了一些东西,但到目前为止已经提出了死胡同.我觉得答案很简单.举个例子:

["abc", "abc", "def", "rty", "rty", "rty", "uig", "ghe", "bed", "abc"]
Run Code Online (Sandbox Code Playgroud)

我想从这里得到2的答案,因为只有两个字符串不止一次在数组中.

aqu*_*nas 5

var list = ["abc", "abc", "def", "rty", "rty", "rty", "uig", "ghe", "bed", "abc"];

var repeatedCount = _.filter(_.groupBy(list), function(n) { return n.length > 1; }).length;
Run Code Online (Sandbox Code Playgroud)