@bbn/bbn 1.0.184 → 1.0.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bbn.js +32 -41
- package/dist/bbn.js.map +1 -1
- package/dist/fn/object/mutateArray.js +31 -39
- package/package.json +1 -1
package/dist/bbn.js
CHANGED
|
@@ -9301,8 +9301,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
9301
9301
|
/* harmony export */ });
|
|
9302
9302
|
/* harmony import */ var _type_isArray_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../type/isArray.js */ "./dist/fn/type/isArray.js");
|
|
9303
9303
|
/* harmony import */ var _string_hash_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../string/hash.js */ "./dist/fn/string/hash.js");
|
|
9304
|
-
/* harmony import */ var _type_isSame_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../type/isSame.js */ "./dist/fn/type/isSame.js");
|
|
9305
|
-
|
|
9306
9304
|
|
|
9307
9305
|
|
|
9308
9306
|
var mutateArray = function (a1, a2) {
|
|
@@ -9310,49 +9308,42 @@ var mutateArray = function (a1, a2) {
|
|
|
9310
9308
|
throw new TypeError('mutateArray can only be called with arrays');
|
|
9311
9309
|
}
|
|
9312
9310
|
var mapA2 = new Map(a2.map(function (item) { return [(0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(item), item]; }));
|
|
9313
|
-
var
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
var a1Key = a1Item ? (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1Item) : undefined;
|
|
9319
|
-
var a2Key = (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a2Item);
|
|
9320
|
-
if (a1Key === a2Key) {
|
|
9321
|
-
// The items match, move both pointers.
|
|
9322
|
-
a1Pointer++;
|
|
9323
|
-
a2Pointer++;
|
|
9324
|
-
}
|
|
9325
|
-
else if (mapA2.has(a1Key)) {
|
|
9326
|
-
// The item in a1 exists in a2 but is out of order, so it should be moved.
|
|
9327
|
-
// First, find the correct position to move it to.
|
|
9328
|
-
var correctIndex = a1.findIndex(function (item) { return (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(item) === a2Key; });
|
|
9329
|
-
var itemToMove = a1.splice(correctIndex, 1)[0];
|
|
9330
|
-
a1.splice(a1Pointer, 0, itemToMove);
|
|
9331
|
-
// Now that the item has been moved to the correct position, move pointers.
|
|
9332
|
-
a1Pointer++;
|
|
9333
|
-
a2Pointer++;
|
|
9334
|
-
}
|
|
9335
|
-
else {
|
|
9336
|
-
// The item in a1 does not exist in a2, so it should be removed.
|
|
9337
|
-
a1.splice(a1Pointer, 1);
|
|
9311
|
+
var a1Ordered = [];
|
|
9312
|
+
// Build a1Ordered to have the same order and contents as a2
|
|
9313
|
+
a2.forEach(function (item) {
|
|
9314
|
+
if (mapA2.has((0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(item))) {
|
|
9315
|
+
a1Ordered.push(item);
|
|
9338
9316
|
}
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9317
|
+
});
|
|
9318
|
+
// Remove items from a1 that are not in a2
|
|
9319
|
+
var i = a1.length;
|
|
9320
|
+
while (i--) {
|
|
9321
|
+
if (!mapA2.has((0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1[i]))) {
|
|
9322
|
+
a1.splice(i, 1);
|
|
9323
|
+
}
|
|
9324
|
+
}
|
|
9325
|
+
var _loop_1 = function (j) {
|
|
9326
|
+
if (j >= a1.length || (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1[j]) !== (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1Ordered[j])) {
|
|
9327
|
+
// Find the index of the item in a1, if it exists
|
|
9328
|
+
var indexInA1 = a1.findIndex(function (item) { return (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(item) === (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1Ordered[j]); });
|
|
9329
|
+
if (indexInA1 !== -1) {
|
|
9330
|
+
// Move the item to the correct position if it already exists in a1
|
|
9331
|
+
var itemToMove = a1.splice(indexInA1, 1)[0];
|
|
9332
|
+
a1.splice(j, 0, itemToMove);
|
|
9333
|
+
}
|
|
9334
|
+
else {
|
|
9335
|
+
// Insert the new item from a2 into a1
|
|
9336
|
+
a1.splice(j, 0, a1Ordered[j]);
|
|
9337
|
+
}
|
|
9344
9338
|
}
|
|
9345
9339
|
};
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
// If there are any remaining items in a1 that are not in a2, remove them.
|
|
9350
|
-
while (a1.length > a2.length) {
|
|
9351
|
-
a1.pop();
|
|
9340
|
+
// Insert or move items to match the order of a2
|
|
9341
|
+
for (var j = 0; j < a1Ordered.length; j++) {
|
|
9342
|
+
_loop_1(j);
|
|
9352
9343
|
}
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9344
|
+
// If a1 has extra items at the end (not present in a2), remove them
|
|
9345
|
+
if (a1.length > a1Ordered.length) {
|
|
9346
|
+
a1.splice(a1Ordered.length, a1.length - a1Ordered.length);
|
|
9356
9347
|
}
|
|
9357
9348
|
return a1;
|
|
9358
9349
|
};
|