列表

详情


JS16. 总成绩排名

描述

请补全JavaScript代码,要求将数组参数中的对象以总成绩(包括属性"chinese"、"math"、"english")从高到低进行排序并返回。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1692ms, 内存消耗: 77812KB, 提交时间: 2022-02-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n        const _rank = array => {\n            // 补全代码\n            array.sort((a,b)=>{\n                let left = a.chinese+a.math+a.english;\n                let right = b.chinese+b.math+b.english;\n                return right-left;\n            })\n            return array;\n        }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1735ms, 内存消耗: 77772KB, 提交时间: 2021-12-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\nconst _rank = array => {\n    array.sort((left, right) => {\n        let lg = left.chinese + left.math + left.english\n        let rg = right.chinese + right.math + right.english\n        return rg - lg\n    })\n    return array\n}\n\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77816KB, 提交时间: 2022-01-22

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n        const _rank = array => {\n            // 补全代码\n            return array.sort((a,b)=>{\n                let A = a.chinese+a.math+a.english\n                let B = b.chinese+b.math+b.english\n                return B - A \n            })\n        }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1742ms, 内存消耗: 77760KB, 提交时间: 2021-12-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n        const _rank = array => {\n            // 补全代码\n            let newArr = []\n            newArr = array.sort(function(a,b) {\n                let as = a.chinese + a.math + a.english\n                let bs = b.chinese + b.math + b.english\n                return bs -as\n            })\n            return newArr\n        }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1742ms, 内存消耗: 77772KB, 提交时间: 2021-12-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n        const _rank = array => {\n            // 补全代码\n            array.sort((a,b)=>{\n                let left = a.chinese+a.math+a.english\n                let right = b.chinese+b.math+b.english\n                return right-left\n            })\n            return array\n        }\n        </script>\n    </body>\n</html>","libs":[]}

上一题