Yes, but that'll be too complex. I have tried the string.compare and it works like wonder! Shave off a lot of computing time.
Thanks a lot! On Wed, Nov 5, 2008 at 5:37 PM, daizi sheng <[EMAIL PROTECTED]> wrote: > > An alternative method is splitting the big string into pieces and > storing such pieces into another data structure like hash table (js > object can be used as hash table). Only when you need the big string, > concate them again. You may not need the whole string very often, I > guess. > > On Wed, Nov 5, 2008 at 5:25 PM, Adrian Godong <[EMAIL PROTECTED]> > wrote: > > Hum, I may be able to use that replace function. Let me check on it. > > > > The problem now is that I have more than 1000 value on the string, it's > very > > slow on the iteration (not on the memory). I presume concatenating > strings > > are slow as usual. > > > > On Wed, Nov 5, 2008 at 5:19 PM, daizi sheng <[EMAIL PROTECTED]> > wrote: > >> > >> 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 > >> > > >> > > > >> > > >> > >> > > > > > > > > -- > > Adrian Godong > > [EMAIL PROTECTED] > > Microsoft MVP > > https://mvp.support.microsoft.com/profile/Adrian > > > > > > > > > > > -- 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 -~----------~----~----~----~------~----~------~--~---