"content":"<p>Write code that enhances all arrays such that you can call the <code>array.groupBy(fn)</code> method on any array and it will return a <strong>grouped</strong> version of the array.</p>\n\n<p>A <strong>grouped</strong> array is an object where each key is the output of <code>fn(arr[i])</code> and each value is an array containing all items in the original array with that key.</p>\n\n<p>The provided callback <code>fn</code> will accept an item in the array and return a string key.</p>\n\n<p>The order of each value list should be the order the items appear in the array. Any order of keys is acceptable.</p>\n\n<p>Please solve it without lodash's <code>_.groupBy</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narray = [\n {"id":"1"},\n {"id":"1"},\n {"id":"2"}\n], \nfn = function (item) { \n return item.id; \n}\n<strong>Output:</strong> \n{ \n "1": [{"id": "1"}, {"id": "1"}], \n "2": [{"id": "2"}] \n}\n<strong>Explanation:</strong>\nOutput is from array.groupBy(fn).\nThe selector function gets the "id" out of each item in the array.\nThere are two objects with an "id" of 1. Both of those objects are put in the first array.\nThere is one object with an "id" of 2. That object is put in the second array.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narray = [\n [1, 2, 3],\n [1, 3, 5],\n [1, 5, 9]\n]\nfn = function (list) { \n return String(list[0]); \n}\n<strong>Output:</strong> \n{ \n "1": [[1, 2, 3], [1, 3, 5], [1, 5, 9]] \n}\n<strong>Explanation:</strong>\nThe array can be of any type. In this case, the selector function defines the key as being the first element in the array. \nAll the arrays have 1 as their first element so they are grouped together.\n{\n "1": [[1, 2, 3], [1, 3, 5], [1, 5, 9]]\n}\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nfn = function (n) { \n return String(n > 5);\n}\n<strong>Output:</strong>\n{\n "true": [6, 7, 8, 9, 10],\n "false": [1, 2, 3, 4, 5]\n}\n<strong>Explanation:</strong>\nThe selector function splits the array by whether each number is greater than 5.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= array.length <= 10<sup>5</sup></code></li>\n\t<li><code>fn</code> returns a string</li>\n</ul>\n",