function lcs(s1, s2) {
let m = Array(s2.length + 1).fill(null).map(() => Array(s1.length + 1).fill(null));
for (let i = 0; i <= s1.length; i += 1) {
m[0][i] = 0;
}
for (let i = 0; i <= s2.length; i += 1) {
m[i][0] = 0;
}
for (let i = 1; i <= s2.length; i += 1) {
for (let j = 1; j <= s1.length; j += 1) {
if (s1[j - 1] === s2[i - 1]) {
m[i][j] = m[i - 1][j - 1] + 1;
} else {
m[i][j] = Math.max(m[i - 1][j], m[i][j - 1]);
}
}
}
return m;
}
console.log(lcs('hello', 'hello'));
console.log(lcs('hello', 'hullo'));
To embed this program on your website, copy the following code and paste it into your website's HTML: