Created
May 1, 2017 19:29
-
-
Save the-vampiire/be38b271fdaaae102eda89e0168b471c to your computer and use it in GitHub Desktop.
fucking bullshit solution
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 characters
| 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