Hokage777,
вариант ...
let val1 = "abc5 abc0 abcde abcfg";
const fn = str => {
let words = str.split(/\s+/).sort((a,b)=> a.length - b.length);
let word = words[0];
for(let a of words){
a = [...a];
let temp = "";
for(b of word){
if(b == a.shift()) temp += b;
else break;
}
if(temp) word = temp;
else return 0
}
return word.length + 1
}
console.log(fn(val1))