Skip to content

Instantly share code, notes, and snippets.

@theuves
Created June 16, 2020 15:23
Show Gist options
  • Save theuves/c042f60ec3833c9f7f2fa340bc949853 to your computer and use it in GitHub Desktop.
Save theuves/c042f60ec3833c9f7f2fa340bc949853 to your computer and use it in GitHub Desktop.
function getChanges(oldText, newText) {
let index
for (let i in oldText) {
let charOld = oldText[i]
let charNew = newText[i]
if (charOld !== charNew) {
index = i
break
}
}
if (index === undefined) {
return {
content: newText.substr(oldText.length),
removeTimes: 0
}
}
return {
content: newText.substr(index),
removeTimes: oldText.length - index
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment