I do not think you method will get problems unless the string is too long.
But will you use too long string in JavaScript?

Anyway, if you really want to get this done more effeciently, I
suggest you to use predefined *replace* functions of String object.


On Wed, Nov 5, 2008 at 3:56 PM, Adrian Godong <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The following question may be simple for you guys, but I do really need
> help.
>
> I have the following application, all the code is Javascript (so you'll miss
> all those powerful library features and server-class computing power).
>
> I need an algorithm improvement for the following scenario:
>
> 1. I have a string of pipe delimited values, e.g. value1|value2|value3
> 2. I will need to find one value, and remove it from the string. For
> instance, I will need to find value2 and remove it from the string so the
> end result would be something like value1|value3
> 3. My current approach is very direct, yet inefficient; split the string
> into array, iterate the array, for each item, I will reconstruct the string
> using string concatenation (e.g. newvalue += currentvalue), if currentvalue
> is equal to the one being removed, I will skip this value and continue with
> the next items.
>
> The problem is, this algorithm is very slow because whatever you remove, it
> will need to iterate the whole array (O(n)). Even worse, if I remove more
> than one value at once, it will iterate the whole array as many times as the
> item being removed.
>
> Anyone have insight about certain algorithm I can use to improve this
> scenario? Keep in mind it's in Javascript.
>
> --
> Adrian Godong
> [EMAIL PROTECTED]
> Microsoft MVP
> https://mvp.support.microsoft.com/profile/Adrian
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to