Status/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)
Created: 02/25/2014
Components: Language
Versions: 11.0
Failure Type: Non Functioning
Found In Build/Fixed In Build: PublicBeta /
Priority/Frequency: Major / Some users will encounter
Locale/System: English / Platforms All
Vote Count: 0
See: http://cfmlblog.adamcameron.me/2014/02/coldfusion-11-map-and-reduce.html
{quote}
This function doesn't work, I'm afraid (or I'm doing something wrong which I cannot identify). We're not off to a good start here. Here's some sample code:
rainbow = "Whero,Karaka,Kowhai,Kakariki,Kikorangi,Tawatawa,Mawhero";
externalList = "";
reverseRainbow = listMap(rainbow,function(v,i,l){
var newValue = "#i#:#v.reverse()#";
externalList = externalList.append(newValue);
return newValue;
});
writeDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]);
externalList = "";
reverseRainbow = rainbow.map(function(v,i,l){
var newValue = "#i#:#v.reverse()#";
externalList = externalList.append(newValue);
return newValue;
});
writeDump([{rainbow=rainbow},{reverseRainbow=reverseRainbow},{externalList=externalList}]);
This contains the same example using both the listMap() function, and the .map() method. Here's the output:
array
1
struct
RAINBOW
Whero,Karaka,Kowhai,Kakariki,Kikorangi,Tawatawa,Mawhero
2
struct
REVERSERAINBOW
Whero,Karaka,Kowhai,Kakariki,Kikorangi,Tawatawa,Mawhero
3
struct
EXTERNALLIST
1:orehW,2:akaraK,3:iahwoK,4:ikirakaK,5:ignarokiK,6:awatawaT,7:orehwaM
array
1
struct
RAINBOW
Whero,Karaka,Kowhai,Kakariki,Kikorangi,Tawatawa,Mawhero
2
struct
REVERSERAINBOW
Whero,Karaka,Kowhai,Kakariki,Kikorangi,Tawatawa,Mawhero
3
struct
EXTERNALLIST
1:orehW,2:akaraK,3:iahwoK,4:ikirakaK,5:ignarokiK,6:awatawaT,7:orehwaM
I've added in the externalList to show you what reverseRainbow should look like. listMap() is supposed to work that the callback receives the element value, its index, and the whole list as arguments. Then it uses that information however is appropriate to create and return a new element. Here the new element is very contrived: the element index, and its value (reversed).
However the original list is just being returned by listMap() here. That's wrong.
{quote}
--
Adam
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3713038
External Customer Info:
External Company:
External Customer Name: Adam Cameron.
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: