MiniDiff

A 406b text differ in JS

Source code

diff=(f,r,t,n,o,e,h,g,s=f.length,a=r.length,c=s+a,l=[],d=[],v=[],b=[],j=c)=>{for(;j--;)b[j]=[];for(l[c+1]=0,t=0;t<=c&&-1===j;t++)for(n=-t;n<=t&&-1===j;n+=2){for(n===-t||n!==t&&l[n-1+c]<l[n+1+c]?(o=l[n+1+c],h=3):(o=l[n-1+c]+1,h=2),b[o][e=o-n]=h;o<s&&e<a&&f[o]===r[e];)b[++o][++e]=0;l[n+c]=o,o>=s&&e>=a&&(j=t)}for(;s||a;)d.unshift((g=b[s][a])>2?-1:f[s-1]),v.unshift([0,h=r[a-1],-1,h][g]),g<3&&s--,2!=g&&a--;return[d,v]}

API

diff(items_before, items_after); // => [[diff_before], [diff_after]]

(in the output, unchanged items are copied, deleted items are marked with "-1")

Demo