RE: Standard Euphoria Library Project

new topic     » goto parent     » topic index » view thread      » older message » newer message

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
      return s[2..len]
    elsif n=len then
      return s[1..len-1]
    end if
    return s[1..n-1] & s[n+1..len]
  end if
  return {}
end function

That covers it.

-Humberto
> --improved 'remove()' function:
> 
> function remove( integer i, sequence s )
>   -- remove ith element from s
>   integer len
> 
>   len=length(s)
>   if len>0 then      --handles null sequence
>     if i>0 then      --handles i<=0
>       if i>len then  --handles i greater then the
> length of the seq.
>         return s
>       else
>         return s[1..i-1] & s[i+1..len]
>       end if
>     end if
>   end if
>   return ""
> end function
> 
> This should take care of most problems associated
> with removing
> specific elements of a sequence.
> 
> Good luck with it.
> --Al
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu