@extra-array/is-permutation

Checks if array has a permutation. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:] > Similar: [permutation], [permutations], [isPermutation]. > Similar: [isValue], [isPrefix], [isInfix], [isSuffix], [isSubsequence], [isPermutation]. > This is part of package extra-array.

Usage no npm install needed!

<script type="module">
  import extraArrayIsPermutation from 'https://cdn.skypack.dev/@extra-array/is-permutation';
</script>

README

Checks if array has a permutation. :running: :vhs: :package: :moon: :ledger:

Similar: permutation, permutations, isPermutation.
Similar: isValue, isPrefix, isInfix, isSuffix, isSubsequence, isPermutation.
This is part of package extra-array.

array.isPermutation(x, y, [fc], [fm]);
// x:  an array
// y:  permutation?
// fc: map function (v, i, x)
// fm: compare function (a, b)
const array = require('extra-array');

var x = [1, 2, 3, 4];
array.isPermutation(x, [4, 3, 2, 1]);
// true

array.isPermutation(x, [3, -1, -2, 4]);
// false

array.isPermutation(x, [3, -1, -2, 4], (a, b) => Math.abs(a) - Math.abs(b));
// true

array.isPermutation(x, [3, -1, -2, 4], null, v => Math.abs(v));
// true

references