-
Notifications
You must be signed in to change notification settings - Fork 5
hasSubsequence
Subhajit Sahu edited this page May 3, 2023
·
14 revisions
Examine if array has a subsequence.
Similar: randomSubsequence, subsequences, hasSubsequence, searchSubsequence.
Similar: hasValue, hasPrefix, hasInfix, hasSuffix, hasSubsequence, hasPermutation, hasPath.
function hasSubsequence(x, y, fc, fm)
// x: an array
// y: search subsequence
// fc: compare function (a, b)
// fm: map function (v, i, x)
const xarray = require('extra-array');
var x = [1, 2, 3, 4];
xarray.hasSubsequence(x, [2, 4]);
// → true
xarray.hasSubsequence(x, [-2, -4]);
// → false
xarray.hasSubsequence(x, [-2, -4], (a, b) => Math.abs(a) - Math.abs(b));
// → true
xarray.hasSubsequence(x, [-2, -4], null, v => Math.abs(v));
// → true