I don't know if you have a correct server side solution yet. Since it's
a holiday here in Belgium (so I have a little time), I took a shot at
it. I didn't start from any of the other solutions posted, but wrote my
own:
<cfscript>
function ListToRanges(list){
var a = ListToArray(list);
var out = "";
var i = 1;
var max = ArrayLen(a);
for(;i LE max;i=i+1){
if(i IS 1 OR a[i-1] LT a[i] - 1){
out = ListAppend(out,a[i]);
}
else if(i IS max OR a[i+1] GT a[i] + 1){
out = ListAppend(out,a[i],"-");
}
}
return out;
}
</cfscript>
<cfoutput>#ListToRanges("1,2,3,4,5,7,9,10,11,12")#</cfoutput>
Pascal
> -----Original Message-----
> From: Nathan R. Jessop [mailto:[EMAIL PROTECTED]
> Sent: donderdag 20 mei 2004 15:37
> To: CF-Talk
> Subject: RE: **UPDATE** Arrange sequential selections into
> ranges how to???
>
> Hmm...
>
>
> If my var1 is equal to...
>
> <cfset var1 = "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, 55, 56, 57, 58, 59,
> 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
> 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
> 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
> 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
> 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
> 128, 129, 130">
>
>
> I get this for the output:
>
> 1
>
> It should be 1-130
>
>
>
> Still not quite right:
>
> initial : 1,2,3,4,5,6,10,11,12,13,14,20,25,30,31,32,33,50
> desired : 1-6,10-14,20,25,30-33,50
> computed: 1-6,10-14,20-20,25-25,50
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

