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.
해석 : 단어들로 이루어진 하나의 스트링에서 제일 짧은 단어의 길이를 리턴하라. 문장은 공백이 될 수 없고 다른 타입의 데이타는 세지 않아도 된다.
Test.describe("Example tests",_=>{
Test.assertEquals(findShort("bitcoin take over the world maybe who knows perhaps"), 3);
Test.assertEquals(findShort("turns out random test cases are easier than writing out basic ones"), 3);
});
function findShort(s){
let str = s.split(' ');
let mapStr = str.map( a => a.length );
let min = Math.min(...mapStr);
return min;
}
const findShort = s => Math.min(...s.split(' ').map(x => x.length));
function findShort(s) {
return s.split(' ').reduce((min, word) => Math.min(min, word.length), Infinity);
}