a javascript lcs implemention with memoization