📌  相关文章
📜  对数字数组进行排序 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:03.939000             🧑  作者: Mango

代码示例6
const myNumbers = [0, 3.14, 2.718, 13];

myNumbers.sort(function (a, b) {
    return a - b;

    /* If a less than b, a negative number will be returned. 
    It means that a is to be placed before b in the final array. For example:

        a = 0, b = 3.14
        a - b = -3.14

    Received a negative number, so a goes before b */
}); 

console.log(myNumbers); // [0, 2.718, 3.14, 13] — correct