@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 +31 -42
- package/dist/bbn.js.map +1 -1
- package/dist/fn/object/mutateArray.js +30 -40
- 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,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
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
//
|
|
9328
|
-
var
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
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
|
-
|
|
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();
|
|
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
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
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
|
};
|