This was tested on:
- Ubuntu 14.04 x64
- Ubuntu 16.04 x64
/** | |
* @description Groups items from an array into an array of objects, grouped by a property 'prop' name, maintaining original order. Based on functionality of LoDash's 'groupBy' function, but, unlike LoDash, preserves original array's order and returns an array instead of an object. | |
* @param arr {array of objects} - Objects within array should contain a property marked by the 'prop' argument, or else they will be excluded from the output and a warning will be logged. | |
* @param prop {string} Propery to use for grouping. The value of this will be converted to a string when creating group names. | |
*/ | |
var groupByKeepOrder = function(arr, prop) { | |
var newArr = [] // array to return, keeps track of order | |
, wrapObj = {}; // temporary object used for grouping | |
_.forEach(arr, function (item) { |