Oh! Hello. This is my thing I made for usvsth3m.com. Hope y'all like it. HTML5 Webworkers made it possible - sandboxing user-submitted JavaScript so an accidental while(1) or document.write can't kill everything.<p>Do have a look at the source code. Oh, and try turning up your speakers and typing in the Konami code...
Fun distraction. For me it was:<p>30% figuring out the answer, 20% not having my editor shortcuts available, 50% figuring out how to check if a value is a certain type.<p>Am I the only one that gives their functions preconditions that the input is good? To me, throwing up when you're passed a non-number to a sum method is correct behavior.
Could there be a histogram at the end that shows distribution of finishing times? Or at least a leaderboard... I did pretty well [obviously ;)] but I'd like to see where my time falls in relationship to others.<p>I've confirmed that I can, in fact, code under pressure, but to what degree?<p>Other than that, fantastically fun game. My only regret is that it's a one-time game by nature, since obviously the second time around you'd simply be remembering what you did the first time instead of creating it.
I took almost 40 minutes, am I in the wrong profession? I figured out how to do all of them right away but I got stuck on figuring out JS syntax in a few places since I barely ever use it and felt like googling was cheating. I did use google on the last one to see how to check if something's an array. I even ended up checking at one point if something's a number by (!isNaN(n/4) && n+n == 2*n), and checked for being a string or not with if(s.length!=undefined) (I know that returns true for an array as well). Would've been a lot easier with something like Intellisense - coding without it feels almost like I'm blind, after being used to it. That and I thought alert() didn't work until I noticed at the end it actually sent it to the output.
Fun little puzzles. First 4 went pretty quickly (~8:00) and then the last one took ~7 minutes Googling around for this so I could test if a variable was an integer...<p><pre><code> n===+n && n===(n|0)
</code></pre>
Wish I could see my answers after the fact though!<p>Edit: Read the initial requirements of the puzzle, it says sum all the <i>integers</i>, not all the <i>numbers</i>. People using (typeof i[x] == 'number') just got lucky because the test-cases didn't exercise the full requirements of the puzzle ;)<p><pre><code> // i will be an array, containing integers and/or arrays like itself.
// Sum all the integers you find, anywhere in the nest of arrays.</code></pre>
That was fun! I just got in to work so I was properly sleeping. I also rarely use typeof, so I had to look up that 'integer' and 'array' do not exist :)
Also, what was really annoying is the use of 'i' for the argument. That's what I exclusively use for the 'for loop' index! Tripped me up a lot, I had to consciously remind myself every time I accessed the array.
Last 'also', the font is WAY too big for my small screen, the comment never fit in, I had to scroll... So I think I did bad, 12 minutes. But still fun :)
It was a kinda cool thing, although I got some strange behavior when I was using `match` for determining whether the input is a filename - my regex was /.<i>\..</i>/ (and so I did var match = i.match(/.<i>\..</i>/) ), and match[1] was undefined - turned out match[2] was what I wanted, and it was present, but the behavior was incorrect in the reporting console in the game.<p>I finished this in 4 minutes.<p>Edit: looks like HN doesn't like asterisks
there's a truly dubious test case in the File Extension test.<p>file called .htaccess is not filename "" and extension "htaccess" with a "." separating the two. .htaccess is a unix style dotfile. its whole name is ".htaccess" and it has no file extension.
It's problems like 5 that make me sad that IE <9 doesn't have Array.prototype.reduce.<p><pre><code> return i.reduce(function(prev, next) {
if (typeof(next) == "object" && next.length) { return arraySum(next) + prev; }
if (typeof(next) == "number") { return next + prev; }
return prev;
}, 0);
</code></pre>
Something that simple needs to be shimmed on earlier IEs. In fact, I had to look up Array.prototype.reduce for this since I usually use Underscore's. Javascript problems...
The input argument name "i" is really annoying. I always use "i" as for-loop var. Made some mistake on this. But the Game is really great. :D
I got 11 minutes and 14 seconds. Is that slow? The answer to my last solution was like this:<p><pre><code> function arraySum(i) {
var total = 0
for(var x=0; x < i.length; x++) {
if(typeof i[x] == 'object') {
arraySum(i[x])
} else if(typeof i[x] == 'number') {
total += i[x]
}
}
return total
}</code></pre>
Last one reminded me how awful JS is once again. There are 5 different ways to check if an object is an array, some are implementation dependent, and the obvious one doesn't work (typeof x == "array").
I created a CoffeeScript version of it. <a href="http://shovon.github.io/youcantcoffeescriptunderpressure/" rel="nofollow">http://shovon.github.io/youcantcoffeescriptunderpressure/</a>
nice stuff but this is plain wrong!
// return the file extension (with no period) if it has one, otherwise false<p>its like returning error codes in C for errors