Last active
March 7, 2018 16:47
-
-
Save skelet00r/65ba0b0910e88bf1bbed1a88e74e09d8 to your computer and use it in GitHub Desktop.
Revisions
-
James Delibas revised this gist
Mar 7, 2018 . No changes.There are no files selected for viewing
-
James Delibas revised this gist
Mar 7, 2018 . No changes.There are no files selected for viewing
-
James Delibas created this gist
Mar 7, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ function merge(dest, src, discriminator) { if (!discriminator) { return [...dest, ...src]; } const result = [...dest]; src.forEach((s) => { const match = dest.find(d => d[discriminator] === s[discriminator]); if (match) { const oldVal = JSON.stringify(match); const newVal = JSON.stringify(s); if (oldVal !== newVal) { const index = result.indexOf(match); result[index] = s; return; } return; } result.push(s); }); return result; }