This file contains 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
/** | |
* Returns an array of unique Items by applying the supplied function to each of the original list | |
* @param {Object[]} list - The array to consider. | |
* @param {Function} fn - A function used to produce a value to use during comparisons. | |
* @returns {Object[]} The list of unique items. | |
* @example | |
* | |
* uniqBy([{a: 1, c:4}, {a: 2, c:5}, {a: 2, c:5}], item => item['a']); //=> [{a: 1, c:4}, {a: 2, c:5}] | |
*/ | |
const uniqBy = (list, fn) => |
This file contains 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
import groupBy from './groupBy'; | |
/** | |
* Takes an array and returns an array of objects that each objects list elements are all satisfied according to the provided function or a string key. | |
* @param {Object[]} list The array to consider. | |
* @param {(Function|String)} criteria function or a string key | |
* @returns {Object[]} Array of subarray's of objects | |
* @example | |
* | |
* groupWith([{a: 4, b: 1}, {a: 4, b: 3}, {a: 5, b: 1}, {a: 5, b: 3}], 'a'); |
This file contains 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
/** | |
* Returns a grouped Object from a given array of Objects where a certain key of these objects are expected to be the same | |
* what ramda js states as Splits a list into sub-lists stored in an object, based on the result of calling a String-returning | |
* function on each element, and grouping the results according to values returned. | |
* @param {Object[]} list - The array to consider. | |
* @param {(Function|String)} criteria - function or a string key | |
* @returns {(Object.<string, Object[]>| void)} an object where keys are the values of each object's criteria key. | |
* @example | |
* | |
* groupBy([{a: 4, b: 1}, {a: 4, b: 3}, {a: 5, b: 1}, {a: 5, b: 3}], 'a'); |