我有一个包含一定数量字符串的数组,我需要找出有多少字符串不是唯一的 - 与 _.uniq 相反。我已经尝试了一些方法,但到目前为止却遇到了死胡同。我感觉答案很简单。举个例子:
["abc", "abc", "def", "rty", "rty", "rty", "uig", "ghe", "bed", "abc"]
我想从中得到答案 2,因为只有两个字符串在数组中出现多次。
最佳答案
var list = ["abc", "abc", "def", "rty", "rty", "rty", "uig", "ghe", "bed", "abc"];
var repeatedCount = _.filter(_.groupBy(list), function(n) { return n.length > 1; }).length;
关于javascript - lodash/下划线查找数组中非唯一元素的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32423512/