函数库使用小册

97 阅读1分钟

返回长度为40的数组,其中的元素为0和1.

/**
 * @description: 随机 生成长度为length,最大数值为maxNum 的数组
 * @param {type} 最大的数值,数组的长度
 * @return {type} 
 */
function generateArr(maxNum, length) {
    let arr = new Array(length);
    for (let i = 0; i < length; i++) {
        arr[i] = Math.floor(Math.random() * Math.ceil(maxNum+1));
    }
    return arr
}

对象数组去重

var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];

_.uniqWith(objects, _.isEqual);
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] 

需要注意这里不会改变objects

bunyan

{"name":"calculate","hostname":"HIH-D-24157","pid":20704,"level":30,"msg":"offLineWordSimilarity progress:41.01947057536644%","time":"2020-12-16T06:57:41.716Z","v":0} 可以最大程度地输出内容