Skip to content

Commit 547271d

Browse files
committed
Add documentation
1 parent 4fdb390 commit 547271d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/fixed-2d-array.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* width: width of the array
3+
* height: height of the array
4+
* defaultValue: the default value for the array
5+
*/
16
var Fixed2DArray = function Fixed2DArray(width,height,defaultValue) {
27
this._width = width;
38
this._height = height;
@@ -10,6 +15,9 @@ var Fixed2DArray = function Fixed2DArray(width,height,defaultValue) {
1015
}
1116
};
1217

18+
/**
19+
* Throws an Error if the given coordinates are invalid
20+
*/
1321
Fixed2DArray.prototype.validateCoords = function(x,y) {
1422
if(x<0 || y<0 || x>=this._width || y>=this._height) {
1523
throw new Error('fixed-2d-array: the coordinates ('+x+'/'+y+') ' +
@@ -18,11 +26,17 @@ Fixed2DArray.prototype.validateCoords = function(x,y) {
1826
}
1927
};
2028

29+
/**
30+
* Returns the coresponding value for the coordinates
31+
*/
2132
Fixed2DArray.prototype.get = function(x,y) {
2233
this.validateCoords(x,y);
2334
return this._grid[x][y];
2435
};
2536

37+
/**
38+
* Sets the value for the coresponding coorinates
39+
*/
2640
Fixed2DArray.prototype.set = function(x,y,val) {
2741
this.validateCoords(x,y);
2842
this._grid[x][y] = val;

0 commit comments

Comments
 (0)