SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ArrayDeleteAt for several items in an array

    I have a list like "11,15,16,29" and an array with about 50 items in it. I need to delete at position 11, 15, 16 and 29, but when I use ArrayDeleteAt(myArray, 11), the array is re-indexed and so deleting at 15 the next time is actually deleting the 16th element. Is there a way to just delete all of these positions at once? Like an ArrayDeleteAtMulti() ?

  2. #2
    SitePoint Wizard bronze trophy cydewaze's Avatar
    Join Date
    Jan 2006
    Location
    Merry Land, USA
    Posts
    1,096
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you delete in descending order so that the renumbering doesn't affect the positions you're working with?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried and I keep getting this error that says Message: [Empty String] and the traceback says:

    java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:144) at coldfusion.runtime.Array.ArrayDeleteAt(Array.java:214) at coldfusion.runtime.CFPage.ArrayDeleteAt(CFPage.java:491) at ...

    My code looks like this:

    Code:
    // this returns a query
    v = g.queryProductVariations(arguments.manufacturer, arguments.productId);
    
    temp = StructNew();
    temp.finishes = v["finish"].toArray();
    temp.upcs = v["UPC"].toArray();
    temp.skus = v["SKU"].toArray();
    temp.statuses = v["status"].toArray();
    temp.costs = v["cost"].toArray();
    temp.images = v["image"].toArray();
    temp.datesadded = v["dateAdded"].toArray();
    temp.uniqueids = v["uniqueId"].toArray();
    temp.themes = v["theme"].toArray();
    temp.discounts = v["priceDiscount"].toArray();
    temp.masterfinishes = v["masterFinish"].toArray();
    temp.siteids = v["siteIds"].toArray();
    
    for (i = v.RecordCount; i GTE 1; i--) {
    	siteids = v["siteids"][i]; // this looks like "5,25,32,43"
    	if (NOT ListFind(siteids, properties.siteId)) {
    		for (key in temp) {
    			// delete this row out of all arrays
    			ArrayDeleteAt(temp[key], i);
    		}
    	}
    }
    Really, Really, Really frustrating. I miss PHP and Python

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,246
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by The Space Goat View Post
    Code:
    siteids = v["siteids"][i]; // this looks like "5,25,32,43"
    it seems like you did not try cydewaze's suggestion to handle the list items in descending order

    throw a ListSort in there, plz
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The Space Goat View Post
    Code:
    // this returns a query
    v = g.queryProductVariations(arguments.manufacturer, arguments.productId);
    ...
    temp.siteids = v["siteIds"].toArray();
    ...
    siteids = v["siteids"][i]; // this looks like "5,25,32,43"
    	if (NOT ListFind(siteids, properties.siteId)) {
    		for (key in temp) {
    			// delete this row out of all arrays
    			ArrayDeleteAt(temp[key], i);
    		}
    	}
    }
    Maybe I am reading this wrong, but it seems like you are jumping through a lot of hoops to get around the fact that the "siteIds" rows contain a list of values ie "5,25,32,43"? Can't you do the filtering in your base query, or better yet, get restructure the table?

    BTW, ArrayDeleteAt does not work here because the undocumented toArray() method does not return the type of object you think it does. So the ArrayDeleteAt function doesn't accept it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •