meows
Version:
A kittybin of tools.
53 lines (52 loc) • 1.67 kB
TypeScript
/**
* Shallow filters out redundant members.
* @example
* uniques([0, 1, 2, 2, 3, 3]) // => [0, 1, 2, 3]
*/
export declare function uniques(arr: any[]): any[];
/**
* Shallow checks for repeat members.
* @example
* has_repeat([1, 2, 3]) // => false
* has_repeat([1, 2, 1]) // => true
*/
export declare function hasRepeat(arr: any[]): boolean;
/**
* Choose random member in array.
* @example
* randChoose([1, 'a', null]) // => 1
* randChoose([1, 'a', null]) // => null
*/
export declare function randChoose(arr: any[]): any;
/**
* A function for quickly generating arrays populated by a range of integers,
* with an optional skip interval.
*
* @example
* range(3) // => [0, 1, 2, 3]
* range(-3) // => [0, -1, -2, -3]
* range(-2, 2) // => [-2, -1, 0, 1, 2]
* range(2, -2) // => [2, 1, 0, -1, -2]
* range(-10, 10, 5) // => [-10, -5, 0, 5, 10]
* range(10, -10, 5) // => [10, 5, 0, -5, -10]
*/
export declare function range(p0: number, pf?: number, skip?: number): number[];
/**
* Uses `λ` to populate an array of `items` length.
*
* @example
* series(x => 0.5*x**2 + 0.5*x, 5) // => [0, 1, 3, 6, 10]
*/
export declare function series(λ: Function, items?: number): any[];
/**
* Returns a shallow copy of the last value of your array. The default behavior
* is to return `undefined` on an empty array while `throwOnEmpty` is set to
* `false`.
*
* @example
* last([3, 2, 1]) // => 1
* last([3, 2, [1, 0]]) // => [1, 0]
* last([null]) // => null
* last([]) // => undefined if throwOnEmpty is false (!)
*/
export declare function last(arr: any[], throwOnEmpty?: boolean): any;