GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mljs/pad-array: Array padding

BranchesTags
Open more actions menu

Latest commit

 

History

16 Commits
16 Commits

Folders and files

NameName
Last commit message
Last commit date
__tests__
__tests__
 
 
src
src
 
 
.eslintrc.yml
.eslintrc.yml
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
.travis.yml
.travis.yml
 
 
History.md
History.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 

Repository files navigation

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:

  • size: Defines the number of fields that will be expanded. The default value is 1. The possible type values are:
    • Number: If the value is just a number it will expand in all directions with that value.
    • Array of numbers: It will expand in each direction given the values, for the array case the two values are left and right and for the matrix case are left, up, right, down
  • value: Determine how to fill the values, if the value don't match with the next strings, the new values are going to be filled with that value. The default value is 0. The special strings are:
    • 'circular': Pad with circular repetition of elements within the dimension.
    • 'replicate': Pad by repeating border elements of array.
    • 'symmetric': Pad array with mirror reflections of itself. In this case the size shouldn't be bigger than the dimensions.
  • output: Instead of creating a new array, the returned value should be in this variable.

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

  • Miguel Asencio

License

MIT

About

Array padding

Resources

Readme
MIT license
Activity
Custom properties

Stars

2 stars

Watchers

10 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.