Live data from Hacker News

You Can't JavaScript Under Pressure

toys.usvsth3m.com

61–70 of 110 posts

Re: You Can't JavaScript Under Pressure

#61
there's a truly dubious test case in the File Extension test.

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.

Re: You Can't JavaScript Under Pressure

#63
post #49

I got 11 minutes and 14 seconds. Is that slow? The answer to my last solution was like this: function arraySum(i) { var total = 0 for(var x=0; x

~6 minutes and 30 seconds

That was also my final answer. However, I was going for speed and not elegance, after looking at other people's responses with prototypes and all.

Re: You Can't JavaScript Under Pressure

#64
post #42

It's problems like 5 that make me sad that IE 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); 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...

https://github.com/kriskowal/es5-shim

Re: You Can't JavaScript Under Pressure

#65
post #26

Fun distraction. For me it was: 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. 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.

TIL there is no typeof === 'array'. -_-

Re: You Can't JavaScript Under Pressure

#66
post #16

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... n===+n && n===(n|0) Wish I could see my answers after the fact though! Edit: Read the initial requirements of the puzzle, it says sum all the integers , not all the numbers . People using (typeof i[x] == 'number') just got lucky because the test-cases d…

[deleted]

Re: You Can't JavaScript Under Pressure

#67
post #26

Fun distraction. For me it was: 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. 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.

TIL there is no typeof === 'array'. -_-

Array.isArray(yourVariable), yeah, had to mdn that one too.

Re: You Can't JavaScript Under Pressure

#68
post #49

I got 11 minutes and 14 seconds. Is that slow? The answer to my last solution was like this: function arraySum(i) { var total = 0 for(var x=0; x

You must've total+= arraySum(i[x]) right? Otherwise this couldn't work as the result of a deep dive wouldn't be utilized anywhere...

Re: You Can't JavaScript Under Pressure

#69
post #17

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 /. \.. / (and so I did var match = i.match(/. \.. /) ), 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. I finished this in 4 minutes. Edit: looks like HN doesn…

I thought regex was overkill for that one and used: return input.split(".")[1] || "";

I fully anticipated a test case like file.name.ext. Of course, you could still do what you're doing, but it'd be a lot more verbose.

Re: You Can't JavaScript Under Pressure

#70
post #17

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 /. \.. / (and so I did var match = i.match(/. \.. /) ), 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. I finished this in 4 minutes. Edit: looks like HN doesn…

I thought regex was overkill for that one and used: return input.split(".")[1] || "";

What if it had multiple dots? Anyhow, I am on 5 hours of sleep, and already s spent6 hours coding...I just wanted to finish fast.
Post reply on HN