var table =
"3\n\
2DNail 3\n\
4DNail 5\n\
8DNail 10\n\
8DNail 11\n\
4DNail 5\n\
2DNail 2";
var rowData = table.split("\n");
rowData.shift(); //do not need the first number
var oldList = {};
var newList = {};
for (var i = 0; i < rowData.length; i++) {
var tempList = rowData[i].split(" ");
var name = tempList[0];
var price = tempList[1];
if(name in oldList) newList[name] = price;
else oldList[name] = price;
}
for (var key in oldList) {
var difference;
if(oldList[key] != newList[key]) {
difference = (newList[key] - oldList[key] < 0) ? (newList[key] - oldList[key]).toString() : "+" + (newList[key] - oldList[key]).toString();
print(key, difference);
}
}
dmFyIHRhYmxlID0gCiIzXG5cCjJETmFpbCAzXG5cCjRETmFpbCA1XG5cCjhETmFpbCAxMFxuXAo4RE5haWwgMTFcblwKNEROYWlsIDVcblwKMkROYWlsIDIiOwoKdmFyIHJvd0RhdGEgPSB0YWJsZS5zcGxpdCgiXG4iKTsKcm93RGF0YS5zaGlmdCgpOyAvL2RvIG5vdCBuZWVkIHRoZSBmaXJzdCBudW1iZXIKCnZhciBvbGRMaXN0ID0ge307CnZhciBuZXdMaXN0ID0ge307Cgpmb3IgKHZhciBpID0gMDsgaSA8IHJvd0RhdGEubGVuZ3RoOyBpKyspIHsKICAgIHZhciB0ZW1wTGlzdCA9IHJvd0RhdGFbaV0uc3BsaXQoIiAiKTsKICAgIHZhciBuYW1lID0gdGVtcExpc3RbMF07CiAgICB2YXIgcHJpY2UgPSB0ZW1wTGlzdFsxXTsKICAgIAogICAgaWYobmFtZSBpbiBvbGRMaXN0KSBuZXdMaXN0W25hbWVdID0gcHJpY2U7CiAgICBlbHNlIG9sZExpc3RbbmFtZV0gPSBwcmljZTsKfQoKZm9yICh2YXIga2V5IGluIG9sZExpc3QpIHsKICAgIHZhciBkaWZmZXJlbmNlOwogICAgaWYob2xkTGlzdFtrZXldICE9IG5ld0xpc3Rba2V5XSkgewogICAgICAgIGRpZmZlcmVuY2UgPSAobmV3TGlzdFtrZXldIC0gb2xkTGlzdFtrZXldIDwgMCkgPyAobmV3TGlzdFtrZXldIC0gb2xkTGlzdFtrZXldKS50b1N0cmluZygpIDogIisiICsgKG5ld0xpc3Rba2V5XSAtIG9sZExpc3Rba2V5XSkudG9TdHJpbmcoKTsKICAgICAgICBwcmludChrZXksIGRpZmZlcmVuY2UpOwogICAgfQp9