Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if there is enough information about your expected XML output for me to help there, but the <code>users_final</code> result you are looking for can be calculated with a fairly straight forward comparison algorithm. The core algorithm is:</p> <pre><code>difference = (a, b, idFieldName) -&gt; if a[idFieldName] != b[idFieldName] throw new Error("#{idFieldName} values must match.") diff = {} diff[idFieldName] = a[idFieldName] isDifferent = false for key, value of b if key != idFieldName and a[key].toUpperCase() != value.toUpperCase() isDifferent = true diff[key] = value if isDifferent return diff else return false </code></pre> <p><a href="http://coffeescript.org/#try%3ausers%20=%20%0A%20%20#%20actual%20application%20has%2025%20properties%20per%20user%0A%20%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20USERID%3a%20150927,%0A%20%20%20%20%20%20EMAIL%3a%20%27irving.block@email.net%27,%0A%20%20%20%20%20%20FIRSTNAME%3a%20%27Irving%27,%0A%20%20%20%20%20%20LASTNAME%3a%20%27Block%27,%0A%20%20%20%20%20%20COLOR%3a%20%27Green%27%0A%20%20%20%20%7D,%0A%20%20%20%20%7B%0A%20%20%20%20%20%20USERID%3a%201246007,%0A%20%20%20%20%20%20EMAIL%3a%20%27allen.adler@email.net%27,%0A%20%20%20%20%20%20FIRSTNAME%3a%20%27Adler%27,%0A%20%20%20%20%20%20LASTNAME%3a%20%27Allen%27,%0A%20%20%20%20%20%20COLOR%3a%20%27Blue%27%0A%20%20%20%20%7D,%0A%20%20%20%20%7B%0A%20%20%20%20%20%20USERID%3a%201248350,%0A%20%20%20%20%20%20EMAIL%3a%20%27walter.pidgeon@email.net%27,%0A%20%20%20%20%20%20FIRSTNAME%3a%20%27Walter%27,%0A%20%20%20%20%20%20LASTNAME%3a%20%27Pidgeon%27,%0A%20%20%20%20%20%20COLOR%3a%20%27Red%27%0A%20%20%20%20%7D%0A%20%20%5D%0A%0Adb_data%20=%20%0A%20%20%5B%20%0A%20%20%20%20%7B%0A%20%20%20%20%20%20USERID%3a%20150927,%0A%20%20%20%20%20%20EMAIL%3a%20%27irving.block@email.net%27,%0A%20%20%20%20%20%20FIRSTNAME%3a%20%27IRVING%27,%0A%20%20%20%20%20%20LASTNAME%3a%20%27Block%27,%0A%20%20%20%20%20%20COLOR%3a%20%27Orange%27%0A%20%20%20%20%7D,%0A%20%20%20%20%7B%0A%20%20%20%20%20%20USERID%3a%201246007,%0A%20%20%20%20%20%20EMAIL%3a%20%27new.email@somewhere.com%27,%0A%20%20%20%20%20%20FIRSTNAME%3a%20%27Adler%27,%0A%20%20%20%20%20%20LASTNAME%3a%20%27Allen%27,%0A%20%20%20%20%20%20COLOR%3a%20%27Blue%27%0A%20%20%20%20%7D,%0A%20%20%20%20%7B%0A%20%20%20%20%20%20USERID%3a%201248350,%0A%20%20%20%20%20%20EMAIL%3a%20%27walter.pidgeon@email.net%27,%0A%20%20%20%20%20%20FIRSTNAME%3a%20%27Walt%27,%0A%20%20%20%20%20%20LASTNAME%3a%20%27Pidgeon%27,%0A%20%20%20%20%20%20COLOR%3a%20%27Red%27%0A%20%20%20%20%7D%0A%20%20%5D%0A%0Adifference%20=%20%28a,%20b,%20idFieldName%29%20-%3E%0A%20%20if%20a%5BidFieldName%5D%20!=%20b%5BidFieldName%5D%0A%20%20%20%20throw%20new%20Error%28%22#%7BidFieldName%7D%20values%20must%20match.%22%29%0A%20%20diff%20=%20%7B%7D%0A%20%20diff%5BidFieldName%5D%20=%20a%5BidFieldName%5D%0A%20%20isDifferent%20=%20false%0A%20%20for%20key,%20value%20of%20b%0A%20%20%20%20if%20key%20!=%20idFieldName%20and%20a%5Bkey%5D.toUpperCase%28%29%20!=%20value.toUpperCase%28%29%0A%20%20%20%20%20%20isDifferent%20=%20true%0A%20%20%20%20%20%20diff%5Bkey%5D%20=%20value%0A%20%20if%20isDifferent%0A%20%20%20%20return%20diff%0A%20%20else%0A%20%20%20%20return%20false%0A%0AarrayToMap%20=%20%28a,%20idFieldName%29%20-%3E%0A%20%20result%20=%20%7B%7D%0A%20%20for%20row%20in%20a%0A%20%20%20%20if%20result%5Brow%5BidFieldName%5D%5D?%0A%20%20%20%20%20%20throw%20new%20Error%28%22#%7BidFieldName%7D%20values%20must%20be%20unique%22%29%0A%20%20%20%20result%5Brow%5BidFieldName%5D%5D%20=%20row%0A%20%20return%20result%0A%0AidFieldName%20=%20%27USERID%27%0A%0AusersMap%20=%20arrayToMap%28users,%20idFieldName%29%0A%0Ausers_final%20=%20%5B%5D%0Afor%20b%20in%20db_data%0A%20%20a%20=%20usersMap%5Bb%5BidFieldName%5D%5D%0A%20%20diff%20=%20difference%28a,%20b,%20idFieldName%29%0A%20%20if%20diff%0A%20%20%20%20users_final.push%28diff%29%0A%0Aalert%28JSON.stringify%28users_final,%20undefined,%202%29%29%0A" rel="nofollow">Here</a> is a fully working example including using the input you provided... with one exception. I think you have a typo in your <code>users</code> literal. I switched it from <code>CLKEY</code> to <code>USERID</code> so it matches the other rows. Just click on the "Run" button in the upper right hand corner after following the link to see your expected <code>users_final</code> result.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload