Blockland Forums > Modification Help

Way to simplify SwapChar

Pages: << < (2/2)

Treynolds416:


--- Quote from: Ipquarx on May 06, 2012, 07:59:50 PM ---What if %a or %b is 0, and what if they are the same? %b-%a-1 will be -1, and if %a or %b is 0 (meaning the first charachter), it will also try to getsubstr with -1!

--- End quote ---
Not everything has to compensate for human stupidity. Chances are, if you're using the function you probably know how to use it correctly. The most optimized code is Nexus' without the min/max check.

Nexus:


--- Quote from: Daenth on May 06, 2012, 07:52:27 PM ---Shouldn't %b = %temp; be %temp = %b;?

--- End quote ---

er yea whoops


--- Quote from: Ipquarx on May 06, 2012, 07:59:50 PM ---What if %a or %b is 0, and what if they are the same? %b-%a-1 will be -1, and if %a or %b is 0 (meaning the first charachter), it will also try to getsubstr with -1!

--- End quote ---

yea saw that coming a mile away.  As I said I wouldn't even have the which is higher check if I didn't think you would jump on it right away.

Er actually I wonder what would happen if %a is 0 and it does a getsubstr starting from -1 to 0
hopefully it will return empty but I have been surprised by these things before

Destiny/Zack0Wack0:


--- Quote from: Nexus on May 06, 2012, 08:24:02 PM ---er yea whoops

yea saw that coming a mile away.  As I said I wouldn't even have the which is higher check if I didn't think you would jump on it right away.

Er actually I wonder what would happen if %a is 0 and it does a getsubstr starting from -1 to 0
hopefully it will return empty but I have been surprised by these things before

--- End quote ---
It'll probably result in a console error. getSubStr is verbose as hell with its errors.

Ipquarx:

So then there are 3 chances for errors I see here:
if a is 0 (first charachter)
if b is the length of the string minus one (last charachter)
or if a is 1 less than b.

So what's the fastest way to check for all those things, and make adjustments as nessescary?

Pages: << < (2/2)

Go to full version