Live data from Hacker News

You Can't JavaScript Under Pressure

toys.usvsth3m.com

51–60 of 110 posts

Re: You Can't JavaScript Under Pressure

#54
post #48
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…

n % 1 == 0

Tried that first, but that will fail on the "false" case.

Re: You Can't JavaScript Under Pressure

#56
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...

Pretty interesting solution. The first thing that came to my head was a loop, but you just used reduce. What are some scenarios where you would use a reduce over a loop? I use underscore a lot too, and I find myself just using _.each all the time

Re: You Can't JavaScript Under Pressure

#57
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] || "";

Re: You Can't JavaScript Under Pressure

#59
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…

n===~~n
Post reply on HN