Skip to content

Instantly share code, notes, and snippets.

@dedicatedfuture
Created August 3, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedicatedfuture/5c15be63c9bffc5c20f5 to your computer and use it in GitHub Desktop.
Save dedicatedfuture/5c15be63c9bffc5c20f5 to your computer and use it in GitHub Desktop.
function inventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
arr2.forEach(function(a, i1){
var index = -1;
arr1.forEach(function(b, i2){
if(b[1] === a [1]){
index = i2;
}
});
if(index !== -1){
arr1[index][0] += arr2[i1][1];
}else{
arr1.push(arr2[i1]);
}
});
return arr1.sort(function(a, b){
return a[1].localeCompare(b[1]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment