SOURCE

const calcCost = (map)=>{
    let res = {}
    res.total = 0
    const average = (...args) => args.reduce((a, b) => a + b) / args.length;
    res.length = {}
    for(let k in map){
        res[k] = average(...map[k])
        res.length[k] = res.length[k]|| 0
        res.length[k] += map[k].length
        res.total += map[k].length
    }
    return res
}
let map = {
    superpower:[3,4,2,4,3,7,6,6,2,3,4,5,3,3,4,5,6,7,5,5,6,5,7,3,2,2,3,3,3,3],
    location:[4,4,5,5,5,4,5,6,5],
    villian:[5,4,4,3,4,3,4,3,6,3,3,2,4,4,2,1,5,2,7,5,4,3,4,2,7,6,3,2,5,2,5,5],
    equiment:[4,6,2,4,3,3,4,3,2,4,3,3,6,3,5,4,2,4,2,5,5,7,4,6,3,5,4,4,3,2],
    hero:[4,2,3,3,4,4,3,5,6,2,5,6,1,6,2,5,4,5,5,6,2,3,2,3,3,3,5,4,3,7,8]
}
console.log(calcCost(map))

console 命令行工具 X clear

                    
>
console