UNPKG

data-fns

Version:

This library provides utility functions for working with array data that are useful in many contexts, including creative coding. It offers generic functions that perform common operations such as offsetting an array, generating an array based on a callbac

20 lines (19 loc) 716 B
/** * Converts an array of indices to a binary array where the indices are 1 and the other digits are 0. * @param indices An array of indices. * @param length The length of the binary array to be returned. * @returns A binary array where the indices are 1 and the other digits are 0. * @example * // Basic usage * indicesToBinary([0, 2, 4], 5) * // Returns [1, 0, 1, 0, 1] * * // Ignoring negative indices * indicesToBinary([0, -1, 2, -2, 4], 5) * // Returns [1, 0, 1, 0, 1] * * // Indices outside range are ignored * indicesToBinary([0, 2, 4, 6], 5) * // Returns [1, 0, 1, 0, 1] */ export declare const indicesToBinary: (indices: Array<number>, length: number) => Array<number>;