document.addEventListener("click", function (event) {
if (event.target.classList.contains("btn-primary")) {
compare()
}
if (event.target.classList.contains("btn-warning")) {
reset()
}
})
function reset() {
document.getElementById("before").value = ""
document.getElementById("after").value = ""
document.getElementById("result").innerHTML = ""
}
function compare() {
var listA;
var listB;
try {
const jsonString = document.getElementById("before").value
const jsonObject = JSON.parse(jsonString);
listA = jsonObject;
} catch (error) {
alert('Error parsing the Before JSON:', error);
}
try {
const jsonString = document.getElementById("after").value
const jsonObject = JSON.parse(jsonString);
listB = jsonObject;
} catch (error) {
alert('Error parsing the After JSON:', error);
}
const pointChanges = comparePointChanges(listA, listB)
var html = `<div>`
html =
html +
`<label>No Changes</label><span class='result-item'>${pointChanges.nochanges.length}</span><hr />`
html =
html +
`<label>Users Who Lost Points</label><div class='result-item'>${pointChanges.usersRemoved}</div><hr />`
html =
html +
`<label>Points Removed</label><span class='result-item'>${pointChanges.pointsRemoved}</span><hr />`
html =
html +
`<label>Users Who Gained Points</label><div class='result-item'>${pointChanges.usersAdded}</div><hr />`
html =
html +
`<label>Points Added</label><span class='result-item'>${pointChanges.pointsAdded}</span><hr />`
html =
html +
`<label>All Member Changes</label><div class='result-item'><table border=1><tr><th>ID</th><th>Point Change</th></tr>`
pointChanges.changes.forEach((element) => html = html +`<tr><td>${element.MembershipID}</td><td>${element.pointChange}</td></tr>` )
html = html + `</table></div></div>`
document.getElementById("result").innerHTML = html
}
function comparePointChanges(
array1,
array2,
idKey...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.