Comparing version 0.2.6 to 0.2.7
@@ -177,1 +177,10 @@ /** | ||
export declare function toObject<T>(items: T[], nameKey?: string, valueKey?: string): {}; | ||
/** | ||
Groups contiguous equivalent items together. | ||
I.e., if equal(items[i], items[i + 1]) returns true, then items[i] and | ||
items[i + 1] will end up in the same sublist. | ||
Returns a regrouping of items that, if flattened, would be equivalent to items. | ||
*/ | ||
export declare function groupSequential<T>(items: T[], areEqual?: (a: T, b: T) => boolean): T[][]; |
32
index.js
@@ -325,1 +325,33 @@ /** | ||
exports.toObject = toObject; | ||
/** | ||
Groups contiguous equivalent items together. | ||
I.e., if equal(items[i], items[i + 1]) returns true, then items[i] and | ||
items[i + 1] will end up in the same sublist. | ||
Returns a regrouping of items that, if flattened, would be equivalent to items. | ||
*/ | ||
function groupSequential(items, areEqual) { | ||
if (areEqual === void 0) { areEqual = function (a, b) { return a === b; }; } | ||
if (items.length === 0) { | ||
return []; | ||
} | ||
var previousItem = items[0]; | ||
var currentSublist = [previousItem]; | ||
var sublists = [currentSublist]; | ||
for (var i = 1, l = items.length; i < l; i++) { | ||
var currentItem = items[i]; | ||
// if comparison returns true, currentItem belongs in the same group as previousItem | ||
if (areEqual(previousItem, currentItem)) { | ||
currentSublist.push(currentItem); | ||
} | ||
else { | ||
// start a new sublist and add it to sublists | ||
currentSublist = [currentItem]; | ||
sublists.push(currentSublist); | ||
} | ||
previousItem = currentItem; | ||
} | ||
return sublists; | ||
} | ||
exports.groupSequential = groupSequential; |
{ | ||
"name": "tarry", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Utility library for manipulating JavaScript Arrays", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16900
474