Shortest Word

Lee·2022년 7월 7일

Algorithm

목록 보기
40/92
post-thumbnail

❓ Shortest Word

Q. Simple, given a string of words, return the length of the shortest word(s).

String will never be empty and you do not need to account for different data types.

✔ Solution

//#my solution
function findShort(s) {
  let result = 0;
  const short = s.split(" ").sort((a, b) => a.length - b.length);
  return short[0].length;
}


//#other solution
function findShort(s){
  return Math.min.apply(null, s.split(' ').map(w => w.length));
}
profile
Lee

0개의 댓글