strs은 단어가 담긴 배열입니다.
공통된 시작 단어(prefix)를 반환해주세요.
예를 들어
strs = ['start', 'stair', 'step']
return은 'st'
strs = ['start', 'wework', 'today']
return은 ''
const getPrefix = strs => {
let string1 = strs[0];
if(strs.length === 0){
string1 = "";
}
for(let i=1; i<strs.length; i++){
while(strs[i].indexOf(string1) !== 0){
string1 = string1.substring(0, string1.length-1)
}
}
return string1;
}