Home

Awesome

pad-array

NPM version build status npm download

Function to fill an array in JavaScript.

This code is based in the MATLAB's code padarray

Installation

npm i ml-pad-array

pad-array(data, [options])

Pads the data array given the current options (returns a new array).

Options:

Examples

var data = [1, 2, 3, 4];

// default case
var default_case = padArray(data);
default_case === [0, 1, 2, 3, 4, 0];

// circular case
var circular_case = padArray(data, { size: 5, value: 'circular' });
circular_case === [4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1];

// replicate case
var replicate_case = padArray(data, { size: 3, value: 'replicate' });
replicate_case === [1, 1, 1, 1, 2, 3, 4, 4, 4, 4];

// symmetric case
var symmetric_case = padArray(data, { size: 3, value: 'symmetric' });
symmetric_case === [3, 2, 1, 1, 2, 3, 4, 4, 3, 2];

Authors

License

MIT