Distinguish between number and object quickly
I have a complex data structure in JavaScript made up of numbers and containers (in this case, arrays). What would be the fastest and / or most efficient way to store and process data? Is there something non-obvious, higher speed and / or memory than, for example, [[1, 2], [3, 4]], which requires something like typeof to distinguish between tree branches and leaves when scanning? The structure is very large, about a million rooms.
I've set up a jsperf benchmark to evaluate some methods for distinguishing between numbers and objects, and typeof seems to be the fastest, except for Opera and IE:
+3
source to share