Because of your comment, HN will have a dozen "I am so disappointed in all of you" posts in the coming week declaring how mean everyone here is, and how it is no longer like it "once was".
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.
Do have a look at the source code. Oh, and try turning up your speakers and typing in the Konami code...
1. Don't use i as the name of the parameter. A lot of people use that as the name of loop variables, and it means breaking habit or wasting time changing the name.
2. For test 3, try some multiple-extension files to make sure they did it right (some.file.multiple.extensions, should return "extensions")
3. For test 5, it says "integers". Try some non-integers during testing, to make sure that it's only checking for integers.
4. For test 5, it says "arrays". Try some objects to make sure they're not being lazy and using typeof thing === "object"
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.
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.
I've confirmed that I can, in fact, code under pressure, but to what degree?
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...
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 didn't exercise the full requirements of the puzzle ;)
// i will be an array, containing integers and/or arrays like itself.
// Sum all the integers you find, anywhere in the nest of arrays.
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 /.\../ (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.
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.
It's problems like 5 that make me sad that IE <9 doesn't have Array.prototype.reduce.
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
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").
Spent nearly the entire time on #3 because I was trying to use String.replace to work and failing. Ended up using .split instead, which passed thanks to poor test coverage (just like at work!).
8:11 for me - as it sounds like was the case with others, the majority of that time was searching for how to check for specific types in Javascript.
For the "is this actually a string?" check, for example, I started looking for the existence of the match method on the object, which of course would have failed if they passed some random object with match defined so I cheated a bit. I'd like to see the full breadth of test options people took out there.
mikeash|12 years ago
corresation|12 years ago
I hope you are happy.
buckbova|12 years ago
https://code.google.com/p/chrome-toolbox/
tomscott|12 years ago
Do have a look at the source code. Oh, and try turning up your speakers and typing in the Konami code...
TazeTSchnitzel|12 years ago
A few suggestions, then:
1. Don't use i as the name of the parameter. A lot of people use that as the name of loop variables, and it means breaking habit or wasting time changing the name.
2. For test 3, try some multiple-extension files to make sure they did it right (some.file.multiple.extensions, should return "extensions")
3. For test 5, it says "integers". Try some non-integers during testing, to make sure that it's only checking for integers.
4. For test 5, it says "arrays". Try some objects to make sure they're not being lazy and using typeof thing === "object"
Anyway, thanks for making this. I love it!
JosephRedfern|12 years ago
TazeTSchnitzel|12 years ago
[deleted]
peeters|12 years ago
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.
dclowd9901|12 years ago
ryanthejuggler|12 years ago
I've confirmed that I can, in fact, code under pressure, but to what degree?
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.
Aco-|12 years ago
https://twitter.com/search?q=I%20completed%20%22You%20Can't%...
cheshire137|12 years ago
brudgers|12 years ago
jenjem|12 years ago
kirse|12 years ago
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 didn't exercise the full requirements of the puzzle ;)
downtowncanada|12 years ago
pretty simple no?
kentor|12 years ago
Justin_Time|12 years ago
It didn't actually require differentiating between integers and floats, just numbers and other types.
unknown|12 years ago
[deleted]
chrisrhoden|12 years ago
Demiurge|12 years ago
robflynn|12 years ago
Bahamut|12 years ago
I finished this in 4 minutes.
Edit: looks like HN doesn't like asterisks
tensafefrogs|12 years ago
return input.split(".")[1] || "";
prezjordan|12 years ago
ianstallings|12 years ago
Cyranix|12 years ago
Absolutely! Being under the gun led me, at one point, to have a "longest string in array" method with a statement like
metaphorm|12 years ago
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.
taternuts|12 years ago
pak|12 years ago
1wheel|12 years ago
dmak|12 years ago
drdrxp|12 years ago
dmak|12 years ago
lighthazard|12 years ago
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.
dclowd9901|12 years ago
ep103|12 years ago
function arraySum(i) { var total = 0 for(var x=0; x < i.length; x++) { if(typeof i[x] == 'object') { total += arraySum(i[x]) } else if(typeof i[x] == 'number') { total += i[x] } } return total }
peregrine|12 years ago
hcarvalhoalves|12 years ago
hayksaakian|12 years ago
or am i missing something?
Bahamut|12 years ago
salehenrahman|12 years ago
axyjo|12 years ago
unknown|12 years ago
[deleted]
jamesroseman|12 years ago
salehenrahman|12 years ago
I used i.forEach for questions involving arrays, instead of for-loops. Saves me time.
leehro|12 years ago
chudi|12 years ago
its like returning error codes in C for errors
jamesroseman|12 years ago
ep103|12 years ago
oftenwrong|12 years ago
Spent nearly the entire time on #3 because I was trying to use String.replace to work and failing. Ended up using .split instead, which passed thanks to poor test coverage (just like at work!).
EdgarVerona|12 years ago
For the "is this actually a string?" check, for example, I started looking for the existence of the match method on the object, which of course would have failed if they passed some random object with match defined so I cheated a bit. I'd like to see the full breadth of test options people took out there.
methodover|12 years ago
I wanna see one of these in Python.
hatsuseno|12 years ago
dpedu|12 years ago
Blew through the first 4 but spent half my time on the last one because I don't have Javascript type checking memorized.
robflynn|12 years ago
The "kill screen" song is stuck in my head now.
nakovet|12 years ago
myh|12 years ago
Justin_Time|12 years ago
dmak|12 years ago
CompelTechnic|12 years ago
mneary|12 years ago
Demiurge|12 years ago
renekooi|12 years ago
trevordixon|12 years ago
ryanthejuggler|12 years ago
Kiro|12 years ago