@bbn/bbn 1.0.185 → 1.0.187

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 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,40 @@ 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 a1Pointer = 0;
9314
- var a2Pointer = 0;
9315
- var _loop_1 = function () {
9316
- var a1Item = a1[a1Pointer];
9317
- var a2Item = a2[a2Pointer];
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);
9338
- }
9339
- // If there's no corresponding item in a1 for the current a2 item, insert it.
9340
- if (a1[a1Pointer] === undefined && a2Pointer < a2.length) {
9341
- a1.splice(a1Pointer, 0, a2Item);
9342
- a1Pointer++;
9343
- a2Pointer++;
9311
+ var a1Ordered = [];
9312
+ // Build a1Ordered to have the same order and contents as a2
9313
+ a2.forEach(function (item) {
9314
+ a1Ordered.push(item);
9315
+ });
9316
+ // Remove items from a1 that are not in a2
9317
+ var i = a1.length;
9318
+ while (i--) {
9319
+ if (!mapA2.has((0,_string_hash_js__WEBPACK_IMPORTED_MODULE_1__.hash)(a1[i]))) {
9320
+ a1.splice(i, 1);
9321
+ }
9322
+ }
9323
+ var _loop_1 = function (j) {
9324
+ 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])) {
9325
+ // Find the index of the item in a1, if it exists
9326
+ 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]); });
9327
+ if (indexInA1 !== -1) {
9328
+ // Move the item to the correct position if it already exists in a1
9329
+ var itemToMove = a1.splice(indexInA1, 1)[0];
9330
+ a1.splice(j, 0, itemToMove);
9331
+ }
9332
+ else {
9333
+ // Insert the new item from a2 into a1
9334
+ a1.splice(j, 0, a1Ordered[j]);
9335
+ }
9344
9336
  }
9345
9337
  };
9346
- while (a2Pointer < a2.length) {
9347
- _loop_1();
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();
9338
+ // Insert or move items to match the order of a2
9339
+ for (var j = 0; j < a1Ordered.length; j++) {
9340
+ _loop_1(j);
9352
9341
  }
9353
- if (!(0,_type_isSame_js__WEBPACK_IMPORTED_MODULE_2__.isSame)(a1, a2)) {
9354
- bbn.fn.log(a1, a2);
9355
- throw new Error('mutateArray failed');
9342
+ // If a1 has extra items at the end (not present in a2), remove them
9343
+ if (a1.length > a1Ordered.length) {
9344
+ a1.splice(a1Ordered.length, a1.length - a1Ordered.length);
9356
9345
  }
9357
9346
  return a1;
9358
9347
  };