Skip to content

Instantly share code, notes, and snippets.

@ForbesLindesay
Created August 16, 2012 09:37
Show Gist options
  • Save ForbesLindesay/3368836 to your computer and use it in GitHub Desktop.
Save ForbesLindesay/3368836 to your computer and use it in GitHub Desktop.
Compare two strings really carefully to work out what's different
function longCompare(actual, expected) {
function format(str) {
if (typeof str === 'string') {
return JSON.stringify(str).replace(/^\"/g, '\'').replace(/\"$/g, '\'');
} else {
return str;
}
}
for (var i = 0; i < actual.length || i < expected.length; i++) {
if (actual.charAt(i) !== expected.charAt(i)) {
console.log(format(actual.charAt(i)) + '!=' + format(expected.charAt(i)));
} else {
console.log(format(actual.charAt(i)) + '=' + format(expected.charAt(i)));
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment