strs은 단어가 담긴 배열입니다. 공통된 시작 단어(prefix)를 반환해주세요.
예를 들어 strs = ['start', 'stair', 'step'] return은 'st'
strs = ['start', 'wework', 'today'] return은 ''
strs[0].split('').every(item => {});
const isWord =
strs.filter(word => word.includes(item)).length === strs.length;
if (isWord) {
result += item;
return true;
}
if (strs.length === 0) {
return '';
}
const getPrefix = strs => {
if (strs.length === 0) {
return '';
}
let result = '';
strs[0].split('').every(item => {
const isWord =
strs.filter(word => word.includes(item)).length === strs.length;
if (isWord) {
result += item;
return true;
}
});
return result;
};