JavaScript - 基础面函数 - 找到最短 | 最长的数

 JavaScript  - 基础面函数 -  找到最短 | 最长的数  

返回的是: 这个字符串的长度

弊端: 只能判断 `Number` 类型


// 找到最短的数
function findShort(s){
  return Math.min.apply(null, s.split(' ').map(w => w.length));
}

// 找到最长的数
function findShort(s){
  return Math.max.apply(null, s.split(' ').map(w => w.length));
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章