Код: Выделить всё
function findSuffix(word1, word2) {
drow1 = word1.split("").reverse();
drow2 = word2.split("").reverse();
suffix = [];
let index = 0;
while (true) {
if (drow1[index] == drow2[index]) {
try {
suffix.push(drow1[index]);
index++;
} catch (error) {
return suffix.reverse().join("");
}
} else {
return suffix.reverse().join("");
}
}
}
console.log(findSuffix("sadabcd", "sadajsdgausghabcd"))
Подробнее здесь: https://stackoverflow.com/questions/797 ... wo-strings