JSPM

  • Created
  • Published
  • Downloads 95
  • Score
    100M100P100Q63982F
  • License MIT

Searches from left, for a subsequence.

Package Exports

  • @extra-array/search-subsequence.min

Readme

Searches from left, for a subsequence. 🏃 📼 📦 🌔 📒

Similar: isPrefix, isInfix, isSuffix, isSubsequence. Similar: search, scan, find.
This is part of package extra-array.

This is browserified, minified version of @extra-array/search-subsequence.
It is exported as global variable array_searchSubsequence.
CDN: unpkg, jsDelivr.

iterable.searchSubsequence(x, y, [fc], [fm]);
// x:  an iterable
// y:  search subsequence
// fc: compare function (a, b)
// fm: map function (v, i, x)
// --> start index of subsequence, -1 if not found
const iterable = require('extra-iterable');

var x = [1, 2, 3, 4];
iterable.searchSubsequence(x, [2, 4]);
// 1

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

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

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

references