@bbn/bbn 1.0.186 → 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.
@@ -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');
@@ -8,9 +10,7 @@ var mutateArray = function (a1, a2) {
8
10
  var a1Ordered = [];
9
11
  // Build a1Ordered to have the same order and contents as a2
10
12
  a2.forEach(function (item) {
11
- if (mapA2.has(hash(item))) {
12
- a1Ordered.push(item);
13
- }
13
+ a1Ordered.push(item);
14
14
  });
15
15
  // Remove items from a1 that are not in a2
16
16
  var i = a1.length;
@@ -19,10 +19,11 @@ var mutateArray = function (a1, a2) {
19
19
  a1.splice(i, 1);
20
20
  }
21
21
  }
22
- var _loop_1 = function (j) {
23
- if (j >= a1.length || hash(a1[j]) !== hash(a1Ordered[j])) {
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])) {
24
25
  // Find the index of the item in a1, if it exists
25
- var indexInA1 = a1.findIndex(function (item) { return hash(item) === hash(a1Ordered[j]); });
26
+ var indexInA1 = search(a1, a1Ordered[j]);
26
27
  if (indexInA1 !== -1) {
27
28
  // Move the item to the correct position if it already exists in a1
28
29
  var itemToMove = a1.splice(indexInA1, 1)[0];
@@ -33,10 +34,6 @@ var mutateArray = function (a1, a2) {
33
34
  a1.splice(j, 0, a1Ordered[j]);
34
35
  }
35
36
  }
36
- };
37
- // Insert or move items to match the order of a2
38
- for (var j = 0; j < a1Ordered.length; j++) {
39
- _loop_1(j);
40
37
  }
41
38
  // If a1 has extra items at the end (not present in a2), remove them
42
39
  if (a1.length > a1Ordered.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.186",
3
+ "version": "1.0.188",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",