Last Updated: February 25, 2016
·
559
· dawnerd

Need to use less lines of JS? Assign variables inside arrays

I run a small contest to see what can be done in five lines of code or less. While all JS can be slapped into one line of code, the point of this is to use actual line breaks as needed but to have your app do as much as possible in those five lines.

There's a few rules that I wont go into as the point of this is to show that you can assign variables inside of an array for use elsewhere.

Take a look at the following code:

setInterval(function() {
  console.log([s = [86400000, 3600000, 60000, 1000]][0].map(function(t) {
    return ("0" + [(t===s[0] && (remaining = (future - ~~(+new Date()/1000))*1000)), left = ~~(remaining/t), remaining -= left*t][1]).slice(-2);
  }).join(':'));
}, [1000, future = +new Date()/1000 + 100000][0]);

This really isn't practical for real development use, in fact please don't use it ever outside of code contests.