A simple JSON stringify function which requires Array.prototype.map method.
The following users provided lots of ideas and improvements of the code.
@Kambfhase, @hartrock, @atk, @haochi, @jed
Actually, I just provided a deficient version at first. The other versions were created by these users(especially @atk). You may see the discussion below.
Sorry, both my firefox 5.0 as my node 4.10 installation do indeed return the string
"null"
if called withnull
as parameter. Anyway, if we take out thea&&
ofa&&a.map
, we will soon see is was necessary to avoid complete and utter failure onnull
orundefined
anywhere within the input - plus we still wouldn't save enough space.We could probably save another byte by replacing the
test?a:0
withtest&&a
within the for-loop.