所以,我希望它能够排序,但事实并非如此。
_.uniq(array, [isSorted], [iteratee], [thisArg])
所以
_.uniq([10,3,13,1,0,2], true);
我运行了它,但它没有排序。我希望它返回:[0,1,2,3,10,13]
最佳答案
这不是 isSorted
参数的作用。
[isSorted] (boolean): Specify the array is sorted. - https://lodash.com/docs#uniq
并不意味着它也会为您对数组进行排序,但如果您将其设置为 true,那么它会期望一个已经排序的数组。
Providing true for isSorted performs a faster search algorithm for sorted arrays.
这是一种优化,因为如果数组已经排序,“创建数组的无重复版本”的算法会快得多。
关于javascript - 为什么这个 lodash uniq isSorted 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30232937/