16_总成绩排名

本题考点:sort

根据题目要求,根据数组参数中的对象属性"chinese"、"math"、"english"之和对数组参数进行排序,核心步骤有:

  1. 对数组参数进行sort排序,sort接受一个函数
  2. 在该函数中声明两个变量,分别用于存储该函数两个对象参数的"chinese"、"math"、"english"属性之和
  3. 最后根据声明的两个变量值对比将数组进行排序

参考答案

const _rank = array => {
    array.sort((left, right) => {
        let lg = left.chinese + left.math + left.english
        let rg = right.chinese + right.math + right.english
        return rg - lg
    })
    return array
}