TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

You Can't JavaScript Under Pressure

72 pointsby jgvover 11 years ago

25 comments

mikeashover 11 years ago
Thanks for immediately playing audio without asking me first. I know everybody just <i>loves</i> it when web pages do that.
评论 #6489239 未加载
评论 #6489516 未加载
tomscottover 11 years ago
Oh! Hello. This is my thing I made for usvsth3m.com. Hope y&#x27;all like it. HTML5 Webworkers made it possible - sandboxing user-submitted JavaScript so an accidental while(1) or document.write can&#x27;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...
评论 #6544182 未加载
评论 #6489401 未加载
评论 #6544183 未加载
peetersover 11 years ago
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&#x27;re passed a non-number to a sum method is correct behavior.
评论 #6489747 未加载
ryanthejugglerover 11 years ago
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&#x27;d like to see where my time falls in relationship to others.<p>I&#x27;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&#x27;s a one-time game by nature, since obviously the second time around you&#x27;d simply be remembering what you did the first time instead of creating it.
评论 #6492510 未加载
cheshire137over 11 years ago
The sudden music&#x2F;talking that started was annoying and caused me to close the tab immediately.
评论 #6489315 未加载
jenjemover 11 years ago
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&#x27;s an array. I even ended up checking at one point if something&#x27;s a number by (!isNaN(n&#x2F;4) &amp;&amp; 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&#x27;ve been a lot easier with something like Intellisense - coding without it feels almost like I&#x27;m blind, after being used to it. That and I thought alert() didn&#x27;t work until I noticed at the end it actually sent it to the output.
kirseover 11 years ago
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 &amp;&amp; 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] == &#x27;number&#x27;) just got lucky because the test-cases didn&#x27;t exercise the full requirements of the puzzle ;)<p><pre><code> &#x2F;&#x2F; i will be an array, containing integers and&#x2F;or arrays like itself. &#x2F;&#x2F; Sum all the integers you find, anywhere in the nest of arrays.</code></pre>
评论 #6489862 未加载
评论 #6489490 未加载
评论 #6489357 未加载
评论 #6489752 未加载
评论 #6489550 未加载
Demiurgeover 11 years ago
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 &#x27;integer&#x27; and &#x27;array&#x27; do not exist :) Also, what was really annoying is the use of &#x27;i&#x27; for the argument. That&#x27;s what I exclusively use for the &#x27;for loop&#x27; index! Tripped me up a lot, I had to consciously remind myself every time I accessed the array. Last &#x27;also&#x27;, 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 :)
评论 #6489423 未加载
Bahamutover 11 years ago
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 &#x2F;.<i>\..</i>&#x2F; (and so I did var match = i.match(&#x2F;.<i>\..</i>&#x2F;) ), 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&#x27;t like asterisks
评论 #6489535 未加载
prezjordanover 11 years ago
Lighten up, everyone, this is a fun little thing. Thanks for sharing.
ianstallingsover 11 years ago
I&#x27;m a bit disappointed that it doesn&#x27;t award points for my heavy use of regex and obscure variable names.
评论 #6489918 未加载
metaphormover 11 years ago
there&#x27;s a truly dubious test case in the File Extension test.<p>file called .htaccess is not filename &quot;&quot; and extension &quot;htaccess&quot; with a &quot;.&quot; separating the two. .htaccess is a unix style dotfile. its whole name is &quot;.htaccess&quot; and it has no file extension.
评论 #6491365 未加载
pakover 11 years ago
It&#x27;s problems like 5 that make me sad that IE &lt;9 doesn&#x27;t have Array.prototype.reduce.<p><pre><code> return i.reduce(function(prev, next) { if (typeof(next) == &quot;object&quot; &amp;&amp; next.length) { return arraySum(next) + prev; } if (typeof(next) == &quot;number&quot;) { 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&#x27;s. Javascript problems...
评论 #6489721 未加载
评论 #6489525 未加载
drdrxpover 11 years ago
The input argument name &quot;i&quot; is really annoying. I always use &quot;i&quot; as for-loop var. Made some mistake on this. But the Game is really great. :D
dmakover 11 years ago
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 &lt; i.length; x++) { if(typeof i[x] == &#x27;object&#x27;) { arraySum(i[x]) } else if(typeof i[x] == &#x27;number&#x27;) { total += i[x] } } return total }</code></pre>
评论 #6489624 未加载
评论 #6489771 未加载
评论 #6489796 未加载
peregrineover 11 years ago
Total bait and switch. As soon as I saw that random array in my array of strings I knew what kind of game this would be.
hcarvalhoalvesover 11 years ago
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&#x27;t work (typeof x == &quot;array&quot;).
评论 #6493061 未加载
评论 #6493422 未加载
salehenrahmanover 11 years ago
I created a CoffeeScript version of it. <a href="http://shovon.github.io/youcantcoffeescriptunderpressure/" rel="nofollow">http:&#x2F;&#x2F;shovon.github.io&#x2F;youcantcoffeescriptunderpressure&#x2F;</a>
axyjoover 11 years ago
&quot;6 minutes, 21 seconds for all 5 levels. Well done!&quot; I feel like I should have done better considering JS is one of my primary languages.
jamesrosemanover 11 years ago
9:10, had to Google a bit for type checking, and I had forgotten the proper syntax for a string split. :-&#x2F;
salehenrahmanover 11 years ago
I got 3 minutes 39 seconds.<p>I used i.forEach for questions involving arrays, instead of for-loops. Saves me time.
leehroover 11 years ago
This was awesome. 5:48. I actually turned my sound on for the end.
chudiover 11 years ago
nice stuff but this is plain wrong! &#x2F;&#x2F; return the file extension (with no period) if it has one, otherwise false<p>its like returning error codes in C for errors
评论 #6489506 未加载
ep103over 11 years ago
What&#x27;s everyone&#x27;s times? I did 7 minutes
评论 #6492442 未加载
评论 #6504935 未加载
评论 #6489460 未加载
评论 #6489327 未加载
评论 #6489602 未加载
评论 #6489416 未加载
评论 #6489509 未加载
评论 #6490953 未加载
评论 #6489306 未加载
评论 #6489541 未加载
评论 #6489408 未加载
评论 #6489317 未加载
评论 #6489481 未加载
评论 #6489436 未加载
评论 #6489426 未加载
评论 #6489501 未加载
Kiroover 11 years ago
Would be great to see some solutions.