hasPermutation - nodef/extra-array GitHub Wiki

Examine if array has a permutation.

Similar: randomPermutation, permutations, hasPermutation. Similar: hasValue, hasPrefix, hasInfix, hasSuffix, hasSubsequence, hasPermutation, hasPath.

function hasPermutation(x, y, fc, fm)
// x:  an array
// y:  search permutation
// fc: map function (v, i, x)
// fm: compare function (a, b)
const xarray = require('extra-array');

var x = [1, 2, 3, 4];
xarray.hasPermutation(x, [4, 3, 2, 1]);
// → true

xarray.hasPermutation(x, [3, -1, -2, 4]);
// → false

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

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

References