From ab793a58b68b2f7c38dcb45eaf60114267e77570 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Sun, 17 Jan 2016 18:52:51 +1300 Subject: [PATCH] Remove goog.array.isSorted --- src/ol/array.js | 13 +++++++++++++ src/ol/source/imagesource.js | 3 +-- src/ol/tilegrid/tilegrid.js | 3 +-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ol/array.js b/src/ol/array.js index 682b78cf98..129b8484f2 100644 --- a/src/ol/array.js +++ b/src/ol/array.js @@ -264,3 +264,16 @@ ol.array.findIndex = function(arr, func, opt_thisArg) { } return -1; } + +ol.array.isSorted = function(arr, opt_func, opt_strict) { + var compare = opt_func || function(a, b) { + return a > b ? 1 : a < b ? -1 : 0; + }; + return arr.every(function(currentVal, index) { + if (index === 0) { + return true; + } + var res = compare(arr[index - 1], currentVal); + return !(res > 0 || opt_strict && res === 0); + }); +} diff --git a/src/ol/source/imagesource.js b/src/ol/source/imagesource.js index 12e4e6b15f..02cd6bc2fd 100644 --- a/src/ol/source/imagesource.js +++ b/src/ol/source/imagesource.js @@ -1,7 +1,6 @@ goog.provide('ol.source.Image'); goog.provide('ol.source.ImageEvent'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events.Event'); goog.require('ol.Attribution'); @@ -52,7 +51,7 @@ ol.source.Image = function(options) { this.resolutions_ = options.resolutions !== undefined ? options.resolutions : null; goog.asserts.assert(!this.resolutions_ || - goog.array.isSorted(this.resolutions_, + ol.array.isSorted(this.resolutions_, function(a, b) { return b - a; }, true), 'resolutions must be null or sorted in descending order'); diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 87df9da396..41ebf2d3c2 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -1,6 +1,5 @@ goog.provide('ol.tilegrid.TileGrid'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.object'); goog.require('ol'); @@ -42,7 +41,7 @@ ol.tilegrid.TileGrid = function(options) { * @type {!Array.} */ this.resolutions_ = options.resolutions; - goog.asserts.assert(goog.array.isSorted(this.resolutions_, function(a, b) { + goog.asserts.assert(ol.array.isSorted(this.resolutions_, function(a, b) { return b - a; }, true), 'resolutions must be sorted in descending order');