tracker issue : CF-4205756

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

structSort callback does not accept non simple values

| View in Tracker

Status/Resolution/Reason: To Fix//Investigate

Reporter/Name(from Bugbase): John W. / ()

Created: 10/31/2019

Components: Functions, Structures

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:

The example above is for structSort but I could see the same use case with arraySort if it's not already there.
Comment by Mark B.
31697 | October 31, 2019 02:48:08 PM GMT
Already works with ArraySort: https://cffiddle.org/app/file?filepath=41dc6fdc-126e-4a27-89bc-820ccc316bd9/97f4abea-8327-4149-b317-81315bcc8032/e64c58d4-0d91-4a16-bdf0-b02f8dc7bf30.cfm
Comment by John W.
31698 | October 31, 2019 03:01:20 PM GMT