Status/Resolution/Reason: To Fix//Investigate
Reporter/Name(from Bugbase): John W. / ()
Created: 10/31/2019
Components: Language, Struct Functions
Versions: 2018
Failure Type:
Found In Build/Fixed In Build: update5 /
Priority/Frequency: Normal /
Locale/System: / Platforms All
Vote Count: 1
Problem Description:
Running the following code causes the error:
Stack Trace
coldfusion.runtime.StructSortValueNotSimpleException: The specified element Thomas does not contain a simple value.
at coldfusion.runtime.StructUtils.StructSort(StructUtils.java:896)
at coldfusion.runtime.CFPage.StructSort(CFPage.java:6806)
{code}
people = {
'Jim': {scores: [10,20,30]},
'Anne': {scores: [1,2,3]},
'Thomas': {scores: [100,200,300]}
};
sorted = people.sort(function(a,b) {
var _a = arrayAvg(a.scores);
var _b = arrayAvg(b.scores);
if (_a != b) {
return _a > _b ? -1 : 1;
}
return 0;
});
writeDump(sorted);
{code}
Steps to Reproduce:
You can run the code above here:
https://cffiddle.org/app/file?filepath=f4e04c67-3ccd-4f0b-816f-264f615352b7/aaca2320-2493-4f28-8600-a3d928c2c23c/8b6b6060-2e30-4bb3-a68b-37cf7bed6f59.cfm
Actual Result:
Stack Trace
coldfusion.runtime.StructSortValueNotSimpleException: The specified element Thomas does not contain a simple value.
at coldfusion.runtime.StructUtils.StructSort(StructUtils.java:896)
at coldfusion.runtime.CFPage.StructSort(CFPage.java:6806)
Expected Result:
An array sorted by the result of the callback function
Any Workarounds:
Iterate the struct and calculate the values and store as a new key/value first before doing the sort.
Attachments:
Comments: