Skip to content

Commit 6100f01

Browse files
committed
Do some formating
1 parent 99bfee7 commit 6100f01

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

lib/fixed-2d-array.js

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Fixed2DArray.prototype.getWidth = function getWidth() {
3737
*
3838
* @param rowNumber {number} number of the row where top left is (0,0).
3939
*/
40-
Fixed2DArray.prototype.getRow = function getRow(rowNumber){
41-
try{
42-
this.validateCoords(0,rowNumber);
43-
} catch(err){
44-
throw new Error('fixed-2d-array: row number '+rowNumber+' is not valid.' +
45-
' The size of this array is ('+this._width+'/'+this._height+')');
40+
Fixed2DArray.prototype.getRow = function getRow(rowNumber) {
41+
try {
42+
this.validateCoords(0, rowNumber);
43+
} catch (err) {
44+
throw new Error('fixed-2d-array: row number ' + rowNumber + ' is not valid.' +
45+
' The size of this array is (' + this._width + '/' + this._height + ')');
4646
}
4747

4848
return this._grid[rowNumber];
@@ -53,12 +53,12 @@ Fixed2DArray.prototype.getRow = function getRow(rowNumber){
5353
*
5454
* @param colNumber {number} number of the column where top left is (0,0).
5555
*/
56-
Fixed2DArray.prototype.getColumn = function getColumn(colNumber){
57-
try{
58-
this.validateCoords(colNumber,0);
59-
} catch(err){
60-
throw new Error('fixed-2d-array: row number '+colNumber+' is not valid.' +
61-
' The size of this array is ('+this._width+'/'+this._height+')');
56+
Fixed2DArray.prototype.getColumn = function getColumn(colNumber) {
57+
try {
58+
this.validateCoords(colNumber, 0);
59+
} catch (err) {
60+
throw new Error('fixed-2d-array: column number ' + colNumber + ' is not valid.' +
61+
' The size of this array is (' + this._width + '/' + this._height + ')');
6262
}
6363

6464
var returnArray = [];
@@ -83,10 +83,10 @@ Fixed2DArray.prototype.getColumn = function getColumn(colNumber){
8383
*
8484
* @param thisArg Optional. Value to use as this when executing callback.
8585
*/
86-
Fixed2DArray.prototype.forEach = function forEach(fn, thisArg){
86+
Fixed2DArray.prototype.forEach = function forEach(fn, thisArg) {
8787
for (var i = 0; i < this._width; i++) {
8888
for (var j = 0; j < this._height; j++) {
89-
fn.call(thisArg, this._grid[i][j], {x: i, y: j}, this);
89+
fn.call(thisArg, this._grid[i][j], { x: i, y: j }, this);
9090
}
9191
}
9292
};
@@ -98,10 +98,9 @@ Fixed2DArray.prototype.forEach = function forEach(fn, thisArg){
9898
* @param y {number} y coordinate
9999
*/
100100
Fixed2DArray.prototype.validateCoords = function validateCoords(x, y) {
101-
if(x<0 || y<0 || x>=this._width || y>=this._height) {
102-
throw new Error('fixed-2d-array: the coordinate ('+x+'/'+y+') ' +
103-
'is not valid.' +
104-
' The size of this array is ('+this._width+'/'+this._height+')');
101+
if (x < 0 || y < 0 || x >= this._width || y >= this._height) {
102+
throw new Error('fixed-2d-array: the coordinate (' + x + '/' + y + ') ' +
103+
'is not valid. The size of this array is (' + this._width + '/' + this._height + ')');
105104
}
106105
};
107106

@@ -112,7 +111,7 @@ Fixed2DArray.prototype.validateCoords = function validateCoords(x, y) {
112111
* @param y {number} y coordinate
113112
*/
114113
Fixed2DArray.prototype.get = function get(x, y) {
115-
this.validateCoords(x,y);
114+
this.validateCoords(x, y);
116115
return this._grid[x][y];
117116
};
118117

@@ -124,7 +123,7 @@ Fixed2DArray.prototype.get = function get(x, y) {
124123
* @param val new value
125124
*/
126125
Fixed2DArray.prototype.set = function set(x, y, val) {
127-
this.validateCoords(x,y);
126+
this.validateCoords(x, y);
128127
this._grid[x][y] = val;
129128
};
130129

@@ -148,25 +147,24 @@ Fixed2DArray.prototype.set = function set(x, y, val) {
148147
* @param y {number} y coordinate
149148
* @param distance {number} length of the neighbor-square around the given coordinate.
150149
*/
151-
Fixed2DArray.prototype.getNeighbours = function getNeighbours(x, y, distance){
152-
this.validateCoords(x,y);
153-
154-
if(typeof distance === 'undefined'){ distance = 1; }
155-
if(distance<=0){
150+
Fixed2DArray.prototype.getNeighbours = function getNeighbours(x, y, distance) {
151+
this.validateCoords(x, y);
152+
153+
if (typeof distance === 'undefined') { distance = 1; }
154+
if (distance <= 0) {
156155
return [];
157156
}
158157

159158
var returnArray = [];
160159

161-
for(var i=x-distance; i<=x+distance; i++){
162-
for(var j=y-distance; j<=y+distance; j++){
160+
for (var i = x - distance; i <= x + distance; i++) {
161+
for (var j = y - distance; j <= y + distance; j++) {
163162
try {
164-
if(!(i===x && j===y)) {
165-
var element = this.get(i,j);
163+
if (!(i === x && j === y)) {
164+
var element = this.get(i, j);
166165
returnArray.push(element);
167166
}
168-
}
169-
catch(e) {
167+
} catch (e) {
170168
//this is a field at the edge of the grid.
171169
//ignore
172170
}
@@ -218,20 +216,17 @@ Fixed2DArray.prototype.getNeighbours = function getNeighbours(x, y, distance){
218216
* @param y2 {number} second y coordinate.
219217
* @param distance {number} Optional. Maximum distance for coordinates to be considered neighbors.
220218
*/
221-
Fixed2DArray.prototype.areNeighbours = function areNeighbours(x1, y1, x2, y2, distance){
222-
this.validateCoords(x1,y1);
223-
this.validateCoords(x2,y2);
219+
Fixed2DArray.prototype.areNeighbours = function areNeighbours(x1, y1, x2, y2, distance) {
220+
this.validateCoords(x1, y1);
221+
this.validateCoords(x2, y2);
224222

225-
if(typeof distance === 'undefined'){ distance = 1; }
226-
if(distance<=0){
223+
if (typeof distance === 'undefined') { distance = 1; }
224+
if (distance <= 0) {
227225
return false;
228226
}
229227

230-
if ( (Math.abs(x1 - x2) <= distance) && (Math.abs(y1 - y2) <= distance) ){
231-
return true;
232-
}else{
233-
return false;
234-
}
228+
229+
return (Math.abs(x1 - x2) <= distance) && (Math.abs(y1 - y2) <= distance);
235230
};
236231

237-
module.exports = Fixed2DArray;
232+
module.exports = Fixed2DArray;

0 commit comments

Comments
 (0)