随笔记录

/**
 * Created by Mloong on 2018/10/27
 */
function randomReward()
{
    //var pIntegral = checkInConfig.pIntegral;
    var pIntegral = [{1: 0.2, 2: 0.3, 3: 0.1}];
    //var randomList = [];
    ////按权重大小排序
    //var weightObj = Object.values(pIntegral[0]).sort();
    ////根据权重找到相应的积分
    //for (let i of weightObj)
    //{
    //    console.log(i);
    //    var shellObj = pIntegral[0];
    //    console.log(shellObj);
    //}

    //for (let j of Object.keys(pIntegral[0]).sort())
    //{
    //    var key = j >> 0;
    //    randomList.push(key);
    //    //if (pIntegral[0][key] < 0.2)
    //    //{
    //    //    randomList.push(key, key, key);
    //    //}
    //}
    //console.log(randomList);
    //var randomValue = randomList[Math.floor(Math.random() * randomList.length)];
    //return randomValue;

    const tools = require("./src/tools")({});
    const lodash = require("lodash")._;
    let newObj = {};
    const max = 1000000;
    console.time("a");

    for (let i = 0; i < max; i++)
    {
        tools.forEach(pIntegral, (item) =>
        {
            newObj = lodash.invert(item);
            //tools.foreach(item, (k, v) =>
            //{
            //    newObj[v] = k;
            //});
        });
    }

    console.timeEnd("a");
    console.log(newObj);
}

randomReward();

  

原文地址:https://www.cnblogs.com/w-s-l123/p/9861378.html