For fun I asked a few friends for ideas on a random color generator in a single line of javascript. You know, these guys: #0afec0
, #c9f2d0
, #9b923e
.
Here’s what we came up in about two minutes (in chronological order)…
1 2 3 |
|
Similar recursive technique, but using a string instead of an array and aliasing the Math object:
1 2 |
|
Using a named function expression instead of arguments.callee.
1 2 |
|
If we assume JavaScript 1.6, then we could just use Array.map():
1 2 |
|
But then, the magic of Math struck (16777215 == ffffff in decimal):
1
|
|
Thx to ben alman, nlogax, and temp01 for their smarts.