@iicoding/utils
Version:
Browser 端 - 类型判断 - 类似 koa 的异步compose - sleep - 扩展对象属性 - 扩展 storage 对象功能
81 lines (80 loc) • 3.18 kB
TypeScript
export type PossibleComposeOptions = {
/**
* @description 传入的数组,最大长度 比如传入[1,...,80],一共是80个数字,如果 max 指定 80 那就刚好符合,超过 80 不被允许
*/
max?: number;
/**
* @description 排除连续相邻数字的位数 比如值为3,则 02 03 04 等连续三位相邻被排除
*/
continuous?: number;
/**
* @description 生成的组合长度 [不能少于指定的最小长度]
*/
minLength?: number;
};
/**
* @summary diff 两个数组 返回相同项的 数组
* @param source 待比对的源数组
* @param target 被比对的目标数组
*/
export declare const arrayDiff: (source: number[], target: number[]) => number[];
/**
* @summary 计算数组中 相邻两位相加的和,如果大于某一值,则 减去某一值, 结果 去重返回
* @param datasource 目标数组
* @param subtractionNumber 对比的值 比如大于 100
*/
export declare const computeNeighborTwoSum: (datasource: number[], subtractionNumber?: number) => number[];
/**
* @summary 1-80 数字中的特殊号码
*/
export declare const specialNumberData: () => number[];
/**
* @summary 随机打乱数组 使用Fisher-Yates算法
* @param arr 目标数组
*/
export declare const shuffle: (arr: number[]) => number[];
/**
* @summary 生成指定长度的顺序数组
* @param length 指定长度
* @param startIndex 是否从其实索引开始
* @example generateNumberArray(3) => [1, 2, 3]
*/
export declare const generateNumberArray: (length: number, startIndex?: boolean) => number[];
/**
* @summary 生成指定长度,指定每个数组项值的数组,
* @param length 指定长度
* @param value 指定的值
* @example generateSpecifyValueAndLengthArray(3, '5') => ['5', '5', '5']
*/
export declare const generateSpecifyValueAndLengthArray: <V = any>(length: number, value: V) => V[];
/**
* @summary 获取 源数组 在 目标数组中的项 返回一个新的数组
* @param source 源数组
* @param target 目标数组
* @example getSourceItemInTarget([1, 2, 3], [2,4,5]) => [2]
*/
export declare const getSourceItemInTarget: (source: number[], target: number[]) => number[];
/**
* 根据对象数组的中的某一个属性排序
* @param source 数据源 object list
* @param sortProperties 排序的属性
* @param defaultValue obj[排序的属性] 的值不存在时 的 默认值
*/
export declare const objectSort: (source: any[], sortProperties: string, defaultValue?: any) => void;
/**
* @summary 过滤原数组得到一个只有 number 类型的结果数组
* @param source
*/
export declare const filterNumberArray: (source: number[]) => number[];
/**
* @summary 根据 C(n,k) 获取组合数
* @description 根据数组分析所有组合的可能性
* @param list 接收的数组
* @param options
*/
export declare const getAllPossibleCompose: (list: number[], options?: PossibleComposeOptions) => number[][];
/**
* @summary 多个数组进行可能性分析之后,进行组合
* @description 多个区域,调用 getAllPossibleCompose 在进行组合
*/
export declare const multiAreaPossibleCompose: () => void;