Skip to content

Instantly share code, notes, and snippets.

@the-vampiire
Created May 1, 2017 19:29
Show Gist options
  • Select an option

  • Save the-vampiire/be38b271fdaaae102eda89e0168b471c to your computer and use it in GitHub Desktop.

Select an option

Save the-vampiire/be38b271fdaaae102eda89e0168b471c to your computer and use it in GitHub Desktop.
fucking bullshit solution
var arr1 = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];
var arr2 = [
[2, "Hair Pin"],
[3, "Half-Eaten Apple"],
[67, "Bowling Ball"],
[7, "Toothpaste"]
];
var merged = arr1.concat(arr2);
var JSON_merged = {};
for(var i in merged){
JSON_merged[merged[i][1]] = merged[i][0];
}
var merged = [];
for(var prop in JSON_merged){
if(JSON_merged.hasOwnProperty(prop)){
merged.push([JSON_merged[prop], prop]);
}
}
console.log(merged);
/* output:
[ [ 67, 'Bowling Ball' ],
[ 2, 'Dirty Sock' ],
[ 2, 'Hair Pin' ],
[ 5, 'Microphone' ],
[ 3, 'Half-Eaten Apple' ],
[ 7, 'Toothpaste' ] ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment