-
Notifications
You must be signed in to change notification settings - Fork 1
searchSubsequence
Subhajit Sahu edited this page Feb 3, 2021
·
14 revisions
Find first index of a subsequence.
Similar: hasPrefix, hasInfix, hasSuffix, hasSubsequence.
Similar: search, [scan], find.
function searchSubsequence(x, y, fc, fm)
// x: an iterable
// y: search subsequence
// fc: compare function (a, b)
// fm: map function (v, i, x)
const xiterable = require('extra-iterable');
var x = [1, 2, 3, 4];
xiterable.searchSubsequence(x, [2, 4]);
// → 1
xiterable.searchSubsequence(x, [-2, -4]);
// → -1
xiterable.searchSubsequence(x, [-2, -4], (a, b) => Math.abs(a) - Math.abs(b));
// → 1
xiterable.searchSubsequence(x, [-2, -4], null, v => Math.abs(v));
// → 1