Last active
October 17, 2017 19:58
-
-
Save allomov/25bdca726ea2d7175cd8050d450e895d to your computer and use it in GitHub Desktop.
This file contains 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 characters
initial = [{ code: "1", size: 0 }, { code: "2", size: 0 }, { code: "3", size: 0 }, { code: "4", size: 0 }] | |
update = [{ code: "1", size: 100 }, { code: "2", size: 100 }, { code: "2", size: 120 }] | |
hash = {} | |
for (let i = 0; i < initial.length; i++) { | |
let o = initial[i]; | |
hash[o.code] = { code: o.code, size: 0 }; | |
} | |
for (let i = 0; i < update.length; i++) { | |
let o = update[i]; | |
hash[o.code].size += o.size; | |
} | |
result = [] | |
for (var key in hash) { | |
result.push(hash[key]) | |
} | |
initial = result |
This file contains 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 characters
initial = [{ code: "1", size: 0 }, { code: "2", size: 0 }, { code: "3", size: 0 }, { code: "4", size: 0 }] | |
update = [{ code: "1", size: 100 }, { code: "2", size: 100 }, { code: "2", size: 120 }] | |
hash = {} | |
for (let i = 0; i < initial.length; i++) { | |
hash[initial[i].code] = initial[i]; | |
} | |
for (let i = 0; i < update.length; i++) { | |
let o = update[i]; | |
hash[o.code].size += o.size; | |
} | |
initial = result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment