2.0.2 • Published 6 years ago

majinbuu v2.0.2

Weekly downloads
23
License
ISC
Repository
github
Last release
6 years ago

Majin Buu

License: ISC Build Status Coverage Status donate

Apply the Levenshtein distance to transform / morph an Array into another, performing the least amount of needed .splice(...) operations.

const abra = ['a', 'b', 'r', 'a'];
majinbuu(abra, ['c', 'a', 'd', 'a', 'b', 'r', 'a']);

abra; // now ['c', 'a', 'd', 'a', 'b', 'r', 'a']

It is also possible to intercept all splice calls using an aura, which augments the splice method of the list, delegating the interceptor one.

const abra = ['a', 'b', 'r', 'a'];
const interceptor = {
  splice(index, removal, ...items) {
    console.log(index, removal, ...items);
    abra.splice.apply(abra, arguments);
  }
};
const aura = majinbuu.aura(interceptor, abra);

majinbuu(aura, ['c', 'a', 'd', 'a', 'b', 'r', 'a']);
// 0 0 "c"
// 2 0 "d" "a"

The optional third argument avoid processing grids that are too big (comparing lists with too many items).

const noMoreThan1K = 1000;
majinbuu(list1, list2, noMoreThan1K);

If the square of the list1 and list2 product is higher than noMoreThan1K, the splice operation will remove all list1 items and push all list2.

Compatibility

Every. JavaScript. Engine.

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago