let arr = ["radog","racecar","racar"] const commonStr =(arr)=>{ let str = arr[0] let comStr ='' for(let i = 0;i<str.length;i++){ let j = 0 for(;j<str.length&&j<arr.length;j++){ if(str[i] != arr[j][i]) { comStr = str.slice(0,i) return comStr } } } } console.log(commonStr(arr))