1. 程式人生 > >隨筆記錄

隨筆記錄

shel 排序 length item math sort pytho {} config

/**
 * 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();

  

隨筆記錄