I need to compare some values of a Javascript object. If they fail to be identical, I want to pretty print to console.log
the mismatch.
The initial code I have written which I find fugly after a JS beautify looks like:
function assert(a, b, message) {
if (a != b) {
console.log("Failed to match " + message + " " + a + " != " + b);
return false;
}
return true;
}
if (!assert(parsedInput.protocol, cu.protocol, "protocol")) {
continue;
}
if (!assert(parsedInput.port, cu.port, "port")) {
continue;
}
if (!assert(parsedInput.hostname, cu.hostname, "hostname")) {
continue;
}
if (!assert(parsedInput.hash, cu.hash, "hash")) {
continue;
}
Please tell me I've missed the plot and I could write this a lot better. Feel free to critique the rest of the code. Thank you!