function longSubstrings(s1, s2, wbr, casesense){
var temp= '', long= [], tem, tem2, str1, str2, len= 2, ax, L, i= 0;
if(s1.length<s2.length){
tem= s1;
s1= s2;
s2= tem;
}
// whole words match faster, if appropriate:
wbr= wbr? ' ':'';
// you can force a case sensitive match:
str1= !casesense? s1.toLowerCase():s1;
str2= !casesense? s2.toLowerCase():s2;
// normalize spaces:
str1= str1.replace(/ {2,}/g, ' ');
str2= str2.replace(/ {2,}/g, ' ');
if(str1.indexOf(str2)!= -1) return s2;
str1= str1.split(wbr);
L= str1.length;
while(i<L){
tem= tem2= str1[i];
ax= str2.indexOf(tem);
while(ax!= -1){
++i;
if(tem2.length>= len){
len= tem2.length;
long= long.filter(function(itm){
return itm.length>= len;
});
long.push(tem2);
}
tem2+= wbr+str1[i];
ax= str2.indexOf(tem2);
}
++i;
}
return long;
}
var s1= 'oie ja s a n y t nc eedjib n ife ks aio m io gna red dogext x ia a dso zcq a a w eadz tie s matsa fw t seno e se pi iz t s j sv b n is t h toa p q osrf o tj e s ine to e io no xo sss jfytai oooic v puieo nnoveya ktnxk atl endtan uiu n s i enhro a a w k s s nlno iai ouex a t pals tnshp ia ais ga dnog rewen z ia bs t bbnn yeq sviiaio tto qe tnoimetn ntsoei i nsut oteh r iynnw ee gos moemtehlt k az q ri svft sc oot naagtc asste nl';
var s2= 'q meael a n o oia d fntqss ne assto nxs n y nx aoeog pho ev t n ao ste o it eoshi j aii x s infs g a il nho t alj ot isw ic ae si k oorateaw ts iug t b oi tn i m e vnos ss o jtn enoik kaon zseeaaitialsu ej a in ays t a nzyv m ibst sxuse t l eto od zs e y os zvinaieks w wq to ce ia ufs v k mrz e n taen d endtbatn tpteiu f gx hboati m o iieac op nef t atyno n p iatb cqaicsn d tt po r oae n n gsq nrne oe ij red doga st eowsiie snhr';
longSubstrings(s1, s2);
//checks by character
// returned value: (Array)
red dog
longSubstrings(s1, s2, 1);
//checks whole words
//returned value: (Array)
red
// Older browsers need a shim for the filter method.
(or just write a loop for the filter)
if(![].filter){
Array.prototype.filter= function(fun, scope){
var T= this, A= [], i= 0, itm, L= T.length;
if(typeof fun== 'function'){
while(i< L){
if(i in T){
itm= T[i];
if(fun.call(scope, itm, i, T)) A[A.length]= itm;
}
++i;
}
}
return A;
}
}
내가 내 대답에 구현을 추가했다. – Pointy