We're updating the issue view to help you get more done. 

built-in functions should work as sort comparators

Description

See http://blog.adamcameron.me/2017/04/cfml-lucee-13-v-4-14-v-6-coldfusion-we.html

See this test case:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 component extends="testbox.system.BaseSpec" { function run() { describe("Other sort tests", function(){ it("is a baseline showing using BIFs as a callback", function(){ var testString = "AbCd"; var applyTo = function(object, operation){ return operation(object); }; var result = applyTo(testString, ucase); expect(result).toBeWithCase("ABCD"); }); describe("using arrays", function(){ it("can use a function expression calling compareNoCase as a string comparator when sorting", function(){ var arrayToSort = ["d","C","b","A"]; arrayToSort.sort(function(e1,e2){ return compareNoCase(e1, e2); }); expect(arrayToSort).toBe(["A","b","C","d"]); }); it("can use the compareNoCase BIF as a string comparator when sorting", function(){ var arrayToSort = ["d","C","b","A"]; arrayToSort.sort(compareNoCase); expect(arrayToSort).toBe(["A","b","C","d"]); }); }); describe("using lists", function(){ it("can use a function expression calling compareNoCase as a string comparator when sorting", function(){ var listToSort = "d,C,b,A"; var sortedList = listToSort.listSort(function(e1,e2){ return compareNoCase(e1, e2); }); expect(sortedList).toBe("A,b,C,d"); expect(listToSort).toBe("d,C,b,A"); }); it("can use the compareNoCase BIF as a string comparator when sorting", function(){ var listToSort = "d,C,b,A"; var sortedList = listToSort.listSort(compareNoCase); expect(sortedList).toBe("A,b,C,d"); expect(listToSort).toBe("d,C,b,A"); }); }); }); } }

Specifically:

1 arrayToSort.sort(compareNoCase);

And:

1 var sortedList = listToSort.listSort(compareNoCase);

Status

Assignee

Michael Offner

Reporter

Adam Cameron

Affects versions

5.1.4.18

Priority

Minor