Skip to content

Commit bde7bdc

Browse files
committed
Improve documentation
1 parent 56a519d commit bde7bdc

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

lib/fixed-2d-array.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/**
2-
* width: width of the array
3-
* height: height of the array
4-
* defaultValue: the default value for the array
2+
* An array with a fixed height and width.
3+
*
4+
* @param width {number} width of the array
5+
* @param height {number} height of the array
6+
* @param defaultValue the initial value for the array elements
7+
* @class
58
*/
69
var Fixed2DArray = function Fixed2DArray(width,height,defaultValue) {
710
this._width = width;
@@ -16,7 +19,10 @@ var Fixed2DArray = function Fixed2DArray(width,height,defaultValue) {
1619
};
1720

1821
/**
19-
* Throws an Error if the given coordinate is invalid
22+
* Throws an Error if the given coordinate is invalid.
23+
*
24+
* @param x {number} x coordinate
25+
* @param y {number} y coordinate
2026
*/
2127
Fixed2DArray.prototype.validateCoords = function(x,y) {
2228
if(x<0 || y<0 || x>=this._width || y>=this._height) {
@@ -27,15 +33,22 @@ Fixed2DArray.prototype.validateCoords = function(x,y) {
2733
};
2834

2935
/**
30-
* Returns the coresponding value for the coordinate
36+
* Returns the value for the coordinate.
37+
*
38+
* @param x {number} x coordinate
39+
* @param y {number} y coordinate
3140
*/
3241
Fixed2DArray.prototype.get = function(x,y) {
3342
this.validateCoords(x,y);
3443
return this._grid[x][y];
3544
};
3645

3746
/**
38-
* Sets the value for the coresponding coorinate
47+
* Sets the value for the coordinate.
48+
*
49+
* @param x {number} x coordinate
50+
* @param y {number} y coordinate
51+
* @param val new value
3952
*/
4053
Fixed2DArray.prototype.set = function(x,y,val) {
4154
this.validateCoords(x,y);
@@ -46,15 +59,20 @@ Fixed2DArray.prototype.set = function(x,y,val) {
4659
* Returns all neighbours of the given coordinate.
4760
*
4861
* For example:
62+
* <pre>
4963
* [ ][ ][ ][ ][ ]
5064
* [ ][*][*][*][ ]
5165
* [ ][*][X][*][ ]
5266
* [ ][*][*][*][ ]
5367
* [ ][ ][ ][ ][ ]
68+
* </pre>
69+
*
70+
* The given coordinate is marked with an `X`.
71+
* The function will return an array containing
72+
* the values for the fields maked with an `*`.
5473
*
55-
* the given coordinate is marked with an `X`
56-
* the function will return an array containing
57-
* the values for the fields maked with an `*`
74+
* @param x {number} x coordinate
75+
* @param y {number} y coordinate
5876
*/
5977
Fixed2DArray.prototype.getNeighbours = function(x,y){
6078
this.validateCoords(x,y);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fixed-2d-array",
3-
"version": "0.0.0",
3+
"version": "1.0.0",
44
"description": "A fixed size 2D array in javascript",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)