From edf4588dfffde665662e35491df820210a1cbe52 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 30 Apr 2014 11:08:42 -0700 Subject: [PATCH] Switch to Array.forEach() where possible --- cameragrid.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cameragrid.js b/cameragrid.js index 1d65876..149d252 100644 --- a/cameragrid.js +++ b/cameragrid.js @@ -201,10 +201,10 @@ CameraGrid.prototype.setSelected_ = function(index) { */ CameraGrid.prototype.buildCells_ = function() { this.cells_ = []; - for (var i = 0; i < this.sourceUrls_.length; i++) { + this.sourceUrls_.forEach(function(sourceUrl) { var cell = document.createElement('cameraGridCell'); this.cells_.push(cell); - } + }, this); }; /** @@ -307,12 +307,11 @@ CameraGrid.prototype.calculateGrid_ = function() { var minCells = Number.MAX_VALUE; var maxScale = 0.0; var chosenHeight, chosenWidth, chosenConstraint = CameraGrid.Dimension.HEIGHT; - for (var i = 0; i < gridOptions.length; i++) { - var gridOption = gridOptions[i]; + gridOptions.forEach(function(gridOption) { var numCells = gridOption[0] * gridOption[1]; if (numCells < numTiles) { // Can't fit all the tiles in (we've rounded down too far). - continue; + return; } var widthScale = (containerWidth / gridOption[0]) / this.tileScaleWidth_; var heightScale = (containerHeight / gridOption[1]) / this.tileScaleHeight_; @@ -326,18 +325,18 @@ CameraGrid.prototype.calculateGrid_ = function() { } if (scale < maxScale) { // This would make cells smaller than another viable solution. - continue; + return; } if (scale == maxScale && numCells > minCells) { // Same cell size as another viable solution, but ours has more cells. - continue; + return; } chosenWidth = gridOption[0]; chosenHeight = gridOption[1]; chosenConstraint = constraint; minCells = numCells; maxScale = scale; - } + }, this); return /** @struct */ { gridWidthCells: chosenWidth, @@ -357,16 +356,15 @@ CameraGrid.prototype.calculateGrid_ = function() { * @private */ CameraGrid.prototype.findMinimumResolution_ = function(tileWidth, tileHeight) { - for (var i = 0; i < this.resolutions_.length; i++) { - var resolution = this.resolutions_[i]; + this.resolutions_.forEach(function(resolution) { if (resolution[0] < tileWidth && resolution[1] < tileHeight) { - continue; + return; } return /** @struct */ { imgWidthPx: resolution[0], imgHeightPx: resolution[1], }; - } + }, this); console.log('Your screen is larger than the largest feed resolution. Images will be scaled up'); var lastResolution = this.resolutions_[this.resolutions_.length - 1]; return {