OpenLayers OpenLayers

Changeset 5543

Show
Ignore:
Timestamp:
12/20/07 15:22:36 (1 year ago)
Author:
pagameba
Message:

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).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Util.js

    r5393 r5543  
    8383 */ 
    8484OpenLayers.Util.removeItem = function(array, item) { 
    85     for(var i=0; i < array.length; i++) { 
     85    for(var i = array.length - 1; i >= 0; i--) { 
    8686        if(array[i] == item) { 
    8787            array.splice(i,1); 
  • trunk/openlayers/tests/test_Util.html

    r5491 r5543  
    1313 
    1414    function test_03_Util_Array(t) { 
    15         t.plan( 1 ); 
    16  
    17         var array = new Array(1,2,3,4,5); 
     15        t.plan( 2 ); 
     16 
     17        var array = new Array(1,2,3,4,4,5); 
    1818 
    1919        OpenLayers.Util.removeItem(array, 3); 
    20         t.eq( array.toString(), "1,2,4,5", "Util.removeItem works");     
     20        t.eq( array.toString(), "1,2,4,4,5", "Util.removeItem works on one element");     
     21        OpenLayers.Util.removeItem(array, 4); 
     22        t.eq( array.toString(), "1,2,5", "Util.removeItem works on more than one element ");     
    2123    } 
    2224