tracker issue : CF-3228672

select a category, or use search below
(searches all categories and all time range)
Title:

ArrayFindAllNoCase

| View in Tracker

Status/Resolution/Reason: Closed/Won't Fix/

Reporter/Name(from Bugbase): Mike Causer / Mike Causer (mike causer)

Created: 07/02/2012

Components: Language, Closures

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / All users will encounter

Locale/System: English / Mac 10.7 64-bit

Vote Count: 2

Problem Description: Documentation states ArrayFindAllNoCase() executes a closure. It appears to not.

ArrayFindAll() checks if the 2nd argument is a UDFMethod and if so, casts the Object as a UDFMethod so that Array.findAll() executes the closure.
ArrayFindAllNoCase() skips this step and calls Array.findAll() without checking/casting.

Steps to Reproduce: ArrayFindAllNoCase(array,function(currentObj) {return true|false;});

Actual Result: empty array

Expected Result: not an empty array

Any Workarounds: call ArrayFindAll() which does not appear to be case sensitive anyway?!

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3228672

External Customer Info:
External Company:  
External Customer Name: mike causer
External Customer Email:  
External Test Config: My Hardware and Environment details: Mac OSX Lion, ColdFusion 10,282462

Attachments:

Comments:

I'm not able to reproduce this. Here's the code: <cfscript> array = ["orange","banana","apple","orange","orange"]; indices = arrayFindAll(array,function(ele) { if(ele == "orange") return true; return false;}); writeDump(indices); </cfscript> Can you let me know the specific case that is failing? (Comment added from ex-user id:sagarg)
Comment by Adobe D.
18819 | September 05, 2012 12:45:26 AM GMT
Hi Sagar, Please try this: <cfscript> array = ["STRING","string"]; indices = arrayFindAllNoCase(array,function(s) { if(s == "string") return true; return false;}); writeDump(indices); </cfscript> Actual Result: empty array Expected result: [1,2] Bug: arrayFindAllNoCase() is broken as Mike said Please try this: <cfscript> array = ["STRING","string"]; indices = arrayFindAll(array,function(s) { if(s == "string") return true; return false;}); writeDump(indices); </cfscript> Actual Result: [1,2] Expected Result: [2] Bug: arrayFind() is not case-sensitive as Mike said Mike raised two bugs in this ticket and both are valid. Your example works b/c it is not related to the two bugs Mike raised. Thanks, -Aaron
Comment by External U.
18820 | September 24, 2012 08:37:17 AM GMT
+1 for fixing both bugs. arrayFindAllNoCase() is broken b/c it always returns an empty array. arrayFindAll() is broken b/c it does not perform a case-sensitive string search.
Vote by External U.
18825 | September 24, 2012 08:39:15 AM GMT
ArrayFindAll and ArrayFindAllNoCase work properly when the second argument is a string. The issues that Mike raised, and which I described, exist when the second parameter to ArrayFindAll and ArrayFindAllNoCase is a function.
Comment by External U.
18821 | September 24, 2012 09:19:32 AM GMT
Please disregard my ArrayFindAll example. The ArrayFindAll documentation is misleading. @Mike, ArrayFindAll is only case-sensitive when the second argument is a simple object (not a function or complex object). I will file a doc bug for ArrayFindAll. @Sagar, ArrayFindAllNoCase still has a problem when the second argument is a function. In this case, ArrayFindAllNoCase always returns an empty array.
Comment by External U.
18822 | September 24, 2012 11:43:21 AM GMT
The problem here is that the "==" operator is not case sensitive, so you can't use it as a case-sensitive test. array = ["orange","banana","apple","ORANGE","orange"]; writeDump(arrayFindAll(array,function(ele) { if(ele == "ORANGE") return true; return false;})); returns: [1,4,5] However, the expected result (because of _not_ using the "NoCase" function variant) would be: [4]. Instead, you should use the compare() function. This makes for less readable code, but does accomplish a case-sensitive search. writeDump( arrayFindAll(array,function(ele) { return (compare("ORANGE", ele) == 0); }) ); However, the bug that arrayFindAllNoCase doesn't work when passed a closure is just that, a bug. It should be fixed. It returns an empty array no matter what the input is. See: array = ["orange","banana","apple","ORANGE","orange"]; indices = arrayFindAllNoCase(array,function(ele) { return true; }); writeDump(indices); returns: []
Comment by External U.
18823 | July 09, 2013 12:47:01 PM GMT
see my comment for reasoning
Vote by External U.
18826 | July 09, 2013 12:47:32 PM GMT
IMO, Closure support for ArrayFindNoCase() or ArrayFindAllNoCase() does not make sense. ArrayFind serves all the purpose. In ArrayFind closure, you get the callback for each element, you do the comparison the way you want, whether in case sensitive way or insensitive way and return the result.
Comment by Rupesh K.
18824 | May 11, 2014 10:11:05 PM GMT