gpt4 book ai didi

javascript - 反向排序列表上的 lodash searchIndex

转载 作者:行者123 更新时间:2023-11-28 00:13:33 37 4
gpt4 key购买 nike

我有一个排序数组,如下所示:

var array = [ 10, 10, 10, 8, 7, 6, 6, 6, 6 ];

我想找到11的插入索引。鉴于此数组按降序排序,插入索引应为0

有没有一种方法可以使用 lodash 来计算此值,而无需再次使用 reverse()sort()

最佳答案

使用 sortedIndex()iteratee 参数否定该项目:

_.sortedIndex(array, 11, function(item) { return -item; });
// → 0

关于javascript - 反向排序列表上的 lodash searchIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30661791/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com