UNPKG

1.12 kBJavaScriptView Raw
1import { comparer as defaultComparer } from '../util/comparer';
2/**
3 * Determines whether two sequences are equal by comparing the elements pairwise.
4 *
5 * @export
6 * @template T The type of the elements in the source sequence.
7 * @param {Iterable<T>} source First iterable sequence to compare.
8 * @param {Iterable<T>} other Second iterable sequence to compare.
9 * @param {SequencEqualOptions<T>} [options] The sequence equal options which include an optional comparer and optional abort signal.
10 * @returns {boolean} A promise which indicates whether both sequences are of equal length and their
11 * corresponding elements are equal.
12 */
13export function sequenceEqual(source, other, options) {
14 const { ['comparer']: comparer = defaultComparer } = options || {};
15 const it1 = source[Symbol.iterator]();
16 const it2 = other[Symbol.iterator]();
17 let next1;
18 let next2;
19 while (!(next1 = it1.next()).done) {
20 if (!(!(next2 = it2.next()).done && comparer(next1.value, next2.value))) {
21 return false;
22 }
23 }
24 return !!it2.next().done;
25}
26
27//# sourceMappingURL=sequenceequal.mjs.map