dorseysen / One-Date-One-Question

this is a space for self-improvement of mine
1 stars 0 forks source link

2019-09-22:从一串只由空格和数字型字符组成的字符串里求出最大数和最小数。难度 ★ #138

Open dorseysen opened 4 years ago

dorseysen commented 4 years ago

// 2019-09-22:从一串只由空格和数字型字符组成的字符串里求出最大数和最小数
// 难度 ★

const getMaxAndMin = str => {

    let arr = str.split(' ').map(item => Number(item));

    return [Math.min.apply(Infinity, arr), Math.max.apply(-Infinity, arr)];
}

return getMaxAndMin('34 56 666 89.1 2 3 4 51 1478.6');