Skip to content

第 5 期(2019-05-12):数组最大数最小数 #7

@wingmeng

Description

@wingmeng

来源:经典算法题
难度:★★

求一个给定数组中的最大数、最小数

/**
 * @param {array} arr - 给定的数组,数组每项为整数
 * @return {array} 返回最大数最小数组成的数组,格式:[max, min]
 */
function findMaxMin(arr) {
  // 你的代码
}

参考答案: 请参阅 @liwenkang 清脆的回答。

另外,如果需要兼容 ES5,可以写成 Math.max.apply(0, arr) Math.min.apply(0, arr)


本期优秀回答者: @liwenkang

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions