Re:Array Iteration Interview Problem
by FrankBooth on Wednesday August 01, 2012 @08:22PM
(#4326519)
Presumably you mean "increment up to abs(n) occurrences", otherwise this requirement is nonsensical.
[ Parent
| on HN ]
yes, that is technically correct (the best kind), however everyone has understood it as intended so far. I also state it like that so as not to give a tip that abs() might be helpful to them down the line.
You could also say -n if you didn't want to say abs. I found the problem confusing because of how it was written.
Also, unless I'm mistaken, you can lose the "if (n === 0)" case completely.
Re:Array Iteration Interview Problem
by revelation on Wednesday August 01, 2012 @08:31PM
(#4326542)
In your code, it is actually completely unnecessary. You have already established that n is < 0, so you could just do "n = -n".