Code: Select all
"80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011"
Code: Select all
"110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011, 80018, 90316"
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Code: Select all
"80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011"
Code: Select all
"110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011, 80018, 90316"
I did forget to mention in the original post (very sorry) that the result is identical regardless of whether or not I am using the "A" or "N" switch.Azhrei wrote:Have you checked the documentation at Wiki: listSort()? There is a parameter which tells the function whether to perform a numeric sort or an alphabetic sort. Yours is an alphabetic sort (hence the one starting with "9" comes after the ones starting with "1").
Thanks for the quick response!Azhrei wrote:Can you show us the pertinent code block? Using "N+" as the second parameter is the correct solution, so maybe there's something else...
Code: Select all
[r:listSort("80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011", "N+")]
Code: Select all
110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011, 80018, 90316
I've come to the same thought from reading the Wiki: listSort() wiki page. Apparently the number is padded to 4 digits rather than actually being converted to a BigDecimal or something. That implies to me that the function will not work if there are any numbers over 9999 in the list.aku wrote:is this an issue with the # of characters?
Code: Select all
[h: list = json.fromList("80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011")]
[h: heap = NumMinHeap.new(list)]
[h: sortedList = ""]
[h, while (json.length(heap) > 0), code:
{
[h: sortedList = listAppend(sortedList, NumMinHeap.get(heap))]
[h: heap = NumMinHeap.pop(heap)]
}]
[r: sortedList]
Code: Select all
50011, 80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515
Code: Select all
[H: list = "80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011"]
[H: jList = ""]
[H, C(listCount(list)): jList = json.append(jList,number(listGet(list,roll.count)))]
[H: jListSorted = json.sort(jList,"a")]
[R: json.toList(jListSorted,"<br>")]
Oh! Oops! I completely missed Wiki: json.sort()! That makes my numeric min-heap kinda superfluous, at least for a one-shot sort algorithm. Oh well.aliasmask wrote:I've been trying to get away from the lists in general when I can use a json in its place. Now when you create your list you do it as a json of number, then you wouldn't have to worry about converting the text to numbers....
Code: Select all
[h: list = json.fromList("80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011")]
[h: sortedList = json.sort(list)]
[r: json.toList(sortedList)]
Code: Select all
50011,80018,90316,110014,130015,200016,220013,270016,360016,440516,440816,472515
Code: Select all
[noEmptyItems = json.difference(bigList,json.append("",""))]
Odd, I tried that first and it still sorted them as a string. Ahhh... I see, I did this:prestidigitator wrote:Yeah, this works just fine:
And produces the output:Code: Select all
[h: list = json.fromList("80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011")] [h: sortedList = json.sort(list)] [r: json.toList(sortedList)]
which is the same as my heap sort, but without the extra whitespace (funny how Wiki: json.toList() and Wiki: listAppend() behave differently there) and is much, much faster.Code: Select all
50011,80018,90316,110014,130015,200016,220013,270016,360016,440516,440816,472515
Code: Select all
[H: jList = json.sort(json.fromList("80018, 90316, 110014, 130015, 200016, 220013, 270016, 360016, 440516, 440816, 472515, 50011"),"a")]
[R: jList]