Array2D is an auxiliary tool to create, manage and manipulate 2d arrays. I made this component to help me develop board game prototypes. If you want to use this component, please! If you want to modify or expand this component, you are welcome to do so. See notes in contribution.
$ npm i Array2D --save
import Array2D from 'array-2d-js'
export default class Map extends Array2D {
constructor (width, height) {
super(width, height)
}
}
or
import Array2D from 'array-2d-js'
const array2D = new Array2D(10, 10)
or
const Array2D = require("array-2d-js")
const array2D = new Array2D(10, 10)
Intitialize Array2D class.
width
Number Number corresponding with the width(column count) of the 2d array.height
Number Number corresponding with the height(row count) of the 2d array.
Return the column of the given position.
position
Number Position for the column.
Returns Array Returns the column.
Add the column at the given position.
position
Number Position for the column.
Remove the column at the given position.
position
Number Position for the column.
Executes the provided function once for each array element for column at given position.
Clear the column at the given position.
position
Number Position for the column.
Condense the 2d array to the minimum by removing all the empty columns on the outside. This process is irreversible.
Get the row of the given position.
position
Number Position for the row.
Returns Array Returns the row.
Add the row at the given position.
position
Number Position for the row.
Remove the row at the given position.
position
Number Position for the row.
Executes the provided function once for each array element for row at given position.
Clear the row at the given position.
position
Number Position for the row.
Condense the 2d array to the minimum by removing all the empty rows on the outside. This process is irreversible.
Get the item of the given position.
Returns any Returns the item.
Fill position with item
x
Number Column position for in the 2d array.y
Number Row position for in the 2d array.item
any Item for in the 2d array.
Clear given position
Find the postion for given item
item
any Item for which you want to find the position.
Returns any Item position.
Executes a provided function once for each 2d array element.
f
function Fill function for the 2d array.
Condense the 2d array to the minimum by removing all the empty rows and columns on the outside. This process is irreversible.
Returns the 2d array.
Returns Array2D Returns the 2d array.
return the width(column count) of the 2d array.
Returns Number Returns the width of the 2d array.
return the height(row count) of the 2d array.
Returns Number Returns the height of the 2d array.
Issues are welcome. The best way to report a problem is to reproduce it with a code example.
Pull requests are welcome. If you want to change the API, it's better to discuss it using an issue ticket.
Array2D is MIT licensed.