UNPKG

@technobuddha/library

Version:
33 lines (32 loc) 1.3 kB
export declare type Options<T> = { /** * Function that acts as a custom comparator * for the array objects. Function should return true if objects are equal, otherwise false. * */ compare?: (a: T, b: T) => boolean; /** * Function used to decide what to return * as a result subsequence. It accepts 2 arguments: index of common element * in the first array and index in the second. The default function returns * element from the first array. */ collect?: (i1: number, i2: number) => T; }; /** * Implementation of Longest Common Subsequence problem. * http://en.wikipedia.org/wiki/Longest_common_subsequence * * Returns the longest possible array that is subarray of both of given arrays. * * @param array1 First array of objects. * @param array2 Second array of objects. * @param __namedParameters see {@link Options} * @default compare equality comparison * @default collect basic collector * @returns A list of objects that are common to both arrays * such that there is no common subsequence with size greater than the * length of the list. */ export declare function longestCommonSubsequence<T>(array1: ArrayLike<T>, array2: ArrayLike<T>, { compare, collect }?: Options<T>): T[]; export default longestCommonSubsequence;