编辑代码

// 竞价规则
const bidRule = {
    minBidPrice: 50,
    maxBidPrice: 500,
    intervalBidPrice: 10
}

// 排名列表
let rankList = [
    { rank: 1, price: 500, name: 'zhao' },
    { rank: 2, price: 500, name: 'qian' },
    { rank: 3, price: 400, name: 'sun' },
    { rank: 4, price: 400, name: 'li' },
    { rank: 5, price: 300, name: 'zhou' },
    { rank: 6, price: 290, name: 'wu' },
    { rank: 7, price: 100, name: 'zheng' },
]


const myBidInfo = rankList[5]


const expectMoneyMap = {}

const { minBidPrice, maxBidPrice, intervalBidPrice } = bidRule

for (let bidPrice = minBidPrice; bidPrice < maxBidPrice + intervalBidPrice; bidPrice += intervalBidPrice) {

    // 预设出价不得低于我当前的出价
    if (bidPrice <= myBidInfo.price) continue

    for (let i = 0; i < rankList.length; i++) {
        const { rank, price } = rankList[i]

        // 当前商家排名不得低于我当前的排名
        if (rank > myBidInfo.rank) continue


        // 预设出价不得低于当前商家出价
        if (bidPrice <= price) continue



        // 不重复计算预设排名
        if (expectMoneyMap[bidPrice] != null) continue

        expectMoneyMap[bidPrice] = {
            price: bidPrice,
            rank: rank
        }


    }
}


const expectMoneyList = Object.values(expectMoneyMap).sort((a, b) => b.price - a.price)

console.log(expectMoneyList)


// [
//     { rank: 3, price: 400, name: 'sun' },
//     { rank: 4, price: 400, name: 'li' },
//     { rank: 5, price: 300, name: 'zhou' },
//     { rank: 6, price: 290, name: 'wu' },
// ]

// 300 6
// 310 5
// 310 6