Skip to content
On this page

Arrays

individual package can be found here @riadh-adrani/array-utils.


isArrayOf()

checks if each element of the array fullfil the provided condition.

ts
function isArrayOf<T>(array: Array<T>, condition: string | ((item: T) => boolean)): boolean;
  • array : the array in question.
  • condition : a type as string (number, string, object ...) or a function, taking taking an element as the only argument and returning boolean.

throws when the condition is neither a string or a function returning a boolean.

range()

creates an array of numbers in the given interval.

ts
function range(start: number, end: number): Array<number>;
  • start : starting number
  • end : ending number.

throws when one or both arguments are not of type number.

throws when end is inferior to start

segmentize()

divide an array into segments and return the result.

ts
function segmentize<T>(array: T[], segmentLength: number): Array<T[]>;
  • array : source array.
  • segmentLength : maximum length of a segment.

shuffle()

shuffle an array an return the result.

The resulting array is not guaranteed to be different from the original one.

ts
function shuffle<T>(input: T[]): T[];
  • input : source array. /

Released under the MIT License.