@bbn/bbn 1.0.181 → 1.0.183
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 +41 -25
- package/dist/bbn.js.map +1 -1
- package/dist/fn/object/mutateArray.js +41 -25
- package/package.json +1 -1
package/dist/bbn.js
CHANGED
|
@@ -9301,41 +9301,57 @@ __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
|
-
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
9305
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
9306
|
-
if (ar || !(i in from)) {
|
|
9307
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
9308
|
-
ar[i] = from[i];
|
|
9309
|
-
}
|
|
9310
|
-
}
|
|
9311
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9312
|
-
};
|
|
9313
9304
|
|
|
9314
9305
|
|
|
9315
9306
|
var mutateArray = function (a1, a2) {
|
|
9316
|
-
if (!(0,_type_isArray_js__WEBPACK_IMPORTED_MODULE_0__.isArray)(a1
|
|
9307
|
+
if (!(0,_type_isArray_js__WEBPACK_IMPORTED_MODULE_0__.isArray)(a1, a2)) {
|
|
9317
9308
|
throw new TypeError('mutateArray can only be called with arrays');
|
|
9318
9309
|
}
|
|
9319
|
-
// Create a map from the second array using the identity function to get the key
|
|
9320
9310
|
var mapA2 = new Map(a2.map(function (item) { return [(0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(item), item]; }));
|
|
9321
|
-
var
|
|
9322
|
-
|
|
9323
|
-
var
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
var
|
|
9327
|
-
var
|
|
9328
|
-
if (
|
|
9329
|
-
//
|
|
9330
|
-
|
|
9311
|
+
var a1Pointer = 0;
|
|
9312
|
+
var a2Pointer = 0;
|
|
9313
|
+
var _loop_1 = function () {
|
|
9314
|
+
var a1Item = a1[a1Pointer];
|
|
9315
|
+
var a2Item = a2[a2Pointer];
|
|
9316
|
+
var a1Key = a1Item ? (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1Item) : undefined;
|
|
9317
|
+
var a2Key = (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a2Item);
|
|
9318
|
+
if (a1Key === a2Key) {
|
|
9319
|
+
// The items match, move both pointers.
|
|
9320
|
+
a1Pointer++;
|
|
9321
|
+
a2Pointer++;
|
|
9322
|
+
}
|
|
9323
|
+
else if (mapA2.has(a1Key)) {
|
|
9324
|
+
// The item in a1 exists in a2 but is out of order, so it should be moved.
|
|
9325
|
+
// First, find the correct position to move it to.
|
|
9326
|
+
var correctIndex = a1.findIndex(function (item) { return (0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(item) === a2Key; });
|
|
9327
|
+
var itemToMove = a1.splice(correctIndex, 1)[0];
|
|
9328
|
+
a1.splice(a1Pointer, 0, itemToMove);
|
|
9329
|
+
// Now that the item has been moved to the correct position, move pointers.
|
|
9330
|
+
a1Pointer++;
|
|
9331
|
+
a2Pointer++;
|
|
9331
9332
|
}
|
|
9332
9333
|
else {
|
|
9333
|
-
//
|
|
9334
|
-
|
|
9334
|
+
// The item in a1 does not exist in a2, so it should be removed.
|
|
9335
|
+
a1.splice(a1Pointer, 1);
|
|
9335
9336
|
}
|
|
9337
|
+
// If there's no corresponding item in a1 for the current a2 item, insert it.
|
|
9338
|
+
if (a1[a1Pointer] === undefined && a2Pointer < a2.length) {
|
|
9339
|
+
a1.splice(a1Pointer, 0, a2Item);
|
|
9340
|
+
a1Pointer++;
|
|
9341
|
+
a2Pointer++;
|
|
9342
|
+
}
|
|
9343
|
+
};
|
|
9344
|
+
while (a2Pointer < a2.length) {
|
|
9345
|
+
_loop_1();
|
|
9346
|
+
}
|
|
9347
|
+
// If there are any remaining items in a1 that are not in a2, remove them.
|
|
9348
|
+
while (a1.length > a2.length) {
|
|
9349
|
+
a1.pop();
|
|
9350
|
+
}
|
|
9351
|
+
if (JSON.stringify(a1) !== JSON.stringify(a2)) {
|
|
9352
|
+
bbn.fn.log(a1, a2);
|
|
9353
|
+
throw new Error('mutateArray failed');
|
|
9336
9354
|
}
|
|
9337
|
-
// Clear a1 and push the ordered results into it
|
|
9338
|
-
a1.splice.apply(a1, __spreadArray([0, a1.length], result, false));
|
|
9339
9355
|
return a1;
|
|
9340
9356
|
};
|
|
9341
9357
|
|