The following script is a small helper that can be useful when you deal with lists or arrays and change the content often. It implements a super simple linked list.
This is a very simple script and some of you may already have a similar utility script. But it appeared that I use this script already very frequently in my scripts and I want to post some other scripts here soon that requires this script.
It is maybe also good to explain the concept of a linked list to beginners.
Features:
- Can be a bit faster than the use of array in some situations ( ie: queues, deleting of many random elements )
- Changing the content of the list while iterating over it is easier/safer, compared to a solution using an array
Usage: see script :)
Note: This is tested in TurboSphere. I am not sure if Sphere1.5 supports the null keyword... but if not it is maybe easy to emulate^^
Note: This is tested in TurboSphere. I am not sure if Sphere1.5 supports the null keyword... but if not it is maybe easy to emulate^^
JavaScript has had a
null keyword since the very first versions. Despite its age, the version of SpiderMonkey in Sphere 1.5 definitely supports it.
Ok, for some reason I thought sphere does not support it. I always avoided to use it in my Sphere code xD
The Sphere editor doesn't highlight it for some reason. I was wary of it at first for the same reason, until I researched JS and found out it was a standard part of the language. Then I just felt dumb. :)
Yea, null exists; I've used it all over my PSG and YM2612 scripts with no problem.
Had some time to checkout what gist is :) -> Updated above ^^