Created
November 11, 2019 14:07
-
-
Save trafficinc/52810a75e8c90c280998b522b1b4392c to your computer and use it in GitHub Desktop.
Get Difference between Two Strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDiff(a, b) { | |
var i = 0; | |
var j = 0; | |
var result = ""; | |
while (j < b.length) { | |
if (a[i] != b[j] || i == a.length) { | |
result += b[j]; | |
} else { | |
i++; | |
} | |
j++; | |
} | |
return result; | |
} | |
console.log(getDiff("Hello World","Hello This World")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment