1 | import id from './_id';
|
2 | import cmp from './_cmp';
|
3 | import type {compareFn, mapFn} from './_types';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function searchSubsequence<T, U=T>(x: Iterable<T>, y: Iterable<T>, fc: compareFn<T|U>=null, fm: mapFn<T, T|U>=null): number {
|
13 | var fc = fc||cmp, fm = fm||id
|
14 | var y1 = [...y].map(fm), Y = y1.length;
|
15 | var a = -1, i = -1, j = 0;
|
16 | for(var u of x) {
|
17 | var u1 = fm(u, ++i, x);
|
18 | if(fc(u1, y1[j])!==0) continue;
|
19 | if(a<0) a = i;
|
20 | if(++j>=Y) return a;
|
21 | }
|
22 | return -1;
|
23 | }
|
24 | export default searchSubsequence;
|