Small patch to removeItem so that all instances of a value in the array are removed, even if they are consecutive by reversing the order in which the array is enumerated. Updated tests and checked in Safari 3, FF2. (closes #1228).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5543 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -82,7 +82,7 @@ OpenLayers.Util.extend = function(destination, source) {
|
|||||||
* {Array} A reference to the array
|
* {Array} A reference to the array
|
||||||
*/
|
*/
|
||||||
OpenLayers.Util.removeItem = function(array, item) {
|
OpenLayers.Util.removeItem = function(array, item) {
|
||||||
for(var i=0; i < array.length; i++) {
|
for(var i = array.length - 1; i >= 0; i--) {
|
||||||
if(array[i] == item) {
|
if(array[i] == item) {
|
||||||
array.splice(i,1);
|
array.splice(i,1);
|
||||||
//break;more than once??
|
//break;more than once??
|
||||||
|
|||||||
@@ -12,12 +12,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_03_Util_Array(t) {
|
function test_03_Util_Array(t) {
|
||||||
t.plan( 1 );
|
t.plan( 2 );
|
||||||
|
|
||||||
var array = new Array(1,2,3,4,5);
|
var array = new Array(1,2,3,4,4,5);
|
||||||
|
|
||||||
OpenLayers.Util.removeItem(array, 3);
|
OpenLayers.Util.removeItem(array, 3);
|
||||||
t.eq( array.toString(), "1,2,4,5", "Util.removeItem works");
|
t.eq( array.toString(), "1,2,4,4,5", "Util.removeItem works on one element");
|
||||||
|
OpenLayers.Util.removeItem(array, 4);
|
||||||
|
t.eq( array.toString(), "1,2,5", "Util.removeItem works on more than one element ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_03_Util_pagePosition(t) {
|
function test_03_Util_pagePosition(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user