RE: Standard Euphoria Library Project
- Posted by Irv Mullins <irvm at ellijay.com> Feb 07, 2001
- 402 views
On Wed, 07 Feb 2001, Humberto wrote: > You're still missing a couple of cases: > > function remove(integer n, sequence s) > integer len > len = length(s) > if len>1 then > if n=1 then -- not needed > return s[2..len] -- not needed > elsif n=len then -- not needed > return s[1..len-1] -- not needed > end if > return s[1..n-1] & s[n+1..len] > end if > return {} > end function > > That covers it. You've somewhat underestimated Euphoria's abilities - all you really need is: sequence s function remove(integer x, sequence s) if x < 1 or x > length(s) then return s end if return s[1..x-1]&s[x+1..length(s)] end function s = "123" for i = -1 to 5 do printf(1, "Removing %d = %s\n", {i,remove(i,s)}) end for Example run: Removing -1 = 123 Removing 0 = 123 Removing 1 = 23 Removing 2 = 13 Removing 3 = 12 Removing 4 = 123 Removing 5 = 123 Regards, Irv