Skip to content

searchSubsequence

Subhajit Sahu edited this page May 3, 2023 · 16 revisions

Find first index of a subsequence.

Similar: randomSubsequence, subsequences, hasSubsequence, searchSubsequence.
Similar: hasValue, hasPrefix, hasInfix, hasSuffix, hasSubsequence, hasPermutation.


function searchSubsequence(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.searchSubsequence(x, [2, 4]);
// → 1

xarray.searchSubsequence(x, [-2, -4]);
// → -1

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

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


References

Clone this wiki locally