Skip to content

Instantly share code, notes, and snippets.

@eyy
Created March 8, 2015 12:48
Show Gist options
  • Save eyy/2a09ef6228edcc2c0100 to your computer and use it in GitHub Desktop.
Save eyy/2a09ef6228edcc2c0100 to your computer and use it in GitHub Desktop.
update array
function updateArray (arr, newArr) {
if (!arr.index)
arr.index = arr.reduce(function(seed, item) {
seed[item.id] = item
return seed
}, {})
newArr.forEach(function(item) {
if (arr.index[item.id])
return _.assign(arr.index[item.id], item)
arr.index[item.id] = item
arr.push(item)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment