@bbn/bbn 1.0.187 → 1.0.188
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 +8 -7
- package/dist/bbn.js.map +1 -1
- package/dist/fn/object/mutateArray.js +6 -7
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { isArray } from '../type/isArray.js';
|
|
2
2
|
import { hash } from '../string/hash.js';
|
|
3
|
+
import { isSame } from '../type/isSame.js';
|
|
4
|
+
import { search } from './search.js';
|
|
3
5
|
var mutateArray = function (a1, a2) {
|
|
4
6
|
if (!isArray(a1, a2)) {
|
|
5
7
|
throw new TypeError('mutateArray can only be called with arrays');
|
|
@@ -17,10 +19,11 @@ var mutateArray = function (a1, a2) {
|
|
|
17
19
|
a1.splice(i, 1);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
// Insert or move items to match the order of a2
|
|
23
|
+
for (var j = 0; j < a1Ordered.length; j++) {
|
|
24
|
+
if ((j >= a1.length) || !isSame(a1[j], a1Ordered[j])) {
|
|
22
25
|
// Find the index of the item in a1, if it exists
|
|
23
|
-
var indexInA1 = a1
|
|
26
|
+
var indexInA1 = search(a1, a1Ordered[j]);
|
|
24
27
|
if (indexInA1 !== -1) {
|
|
25
28
|
// Move the item to the correct position if it already exists in a1
|
|
26
29
|
var itemToMove = a1.splice(indexInA1, 1)[0];
|
|
@@ -31,10 +34,6 @@ var mutateArray = function (a1, a2) {
|
|
|
31
34
|
a1.splice(j, 0, a1Ordered[j]);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
|
-
};
|
|
35
|
-
// Insert or move items to match the order of a2
|
|
36
|
-
for (var j = 0; j < a1Ordered.length; j++) {
|
|
37
|
-
_loop_1(j);
|
|
38
37
|
}
|
|
39
38
|
// If a1 has extra items at the end (not present in a2), remove them
|
|
40
39
|
if (a1.length > a1Ordered.length) {
|