Skip to content

npm module for creating 2D array filled with a given value.

Notifications You must be signed in to change notification settings

colbycolby/matrix-fill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

matrix-fill

NPM Version

Create and fill in 2D Array of any type.

Install

Install with npm:

$ npm install --save matrix-fill

Usage

Returns 2D array of values of any type.

const fill = require('matrix-fill');

console.log(fill('abc', 5, 5))
//=> [ [ 'abc', 'abc', 'abc', 'abc', 'abc' ],
//     [ 'abc', 'abc', 'abc', 'abc', 'abc' ],
//     [ 'abc', 'abc', 'abc', 'abc', 'abc' ],
//     [ 'abc', 'abc', 'abc', 'abc', 'abc' ],
//     [ 'abc', 'abc', 'abc', 'abc', 'abc' ] ]


console.log(fill(5, 5, 5))
//=> [ [ 5, 5, 5, 5, 5 ],
//     [ 5, 5, 5, 5, 5 ],
//     [ 5, 5, 5, 5, 5 ],
//     [ 5, 5, 5, 5, 5 ],
//     [ 5, 5, 5, 5, 5 ] ]


console.log(fill({name: 'steve'}, 3, 3));
// [ [ { name: 'steve' }, { name: 'steve' }, { name: 'steve' } ],
//   [ { name: 'steve' }, { name: 'steve' }, { name: 'steve' } ],
//   [ { name: 'steve' }, { name: 'steve' }, { name: 'steve' } ] ]

Params

fill(value, rows, columns);
  • value: {*} the value to fill the matrix with.
  • rows: {Number} the number of rows in the matrix.
  • columns: {Number} the number of columns in the matrix.

About

npm module for creating 2D array filled with a given value.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published