Hacker Newsnew | past | comments | ask | show | jobs | submit | more azylman's commentslogin

Solution in CoffeeScript:

    add1 = (arr, val, n) ->
      n = arr.length if n is 0
      arr = arr.reverse() if n < 0
      count = 0
      for num, i in arr
        break if count > (Math.abs n)
        arr[i]++ if num is val
        count++
      return if n < 0 then arr.reverse() else arr


another double reverse... I guess coffeescript really does want to be ruby :)


Here's my version without using reverse or underscore. If coffeescript supported reverse loops or negative indices, this would be a lot cleaner.

    add1 = (arr, val, n)->
      d = Math.abs(n||1)/(n||1)
      n = if n is 0 then arr.length else Math.abs n
      i = if d < 0 then arr.length - 1 else 0
      end = if d < 0 then 0 else arr.length

      while n and i isnt end
        num = arr[i]
        if num is val
          n--
          arr[i]++
        i = i + d
      arr


Here's my cheating version that uses a third-party library:

    add1_cheating = (arr, val, n) ->
      n = arr.length if n is 0
      start = if n < 0 then arr.length else 0
      end = if n < 0 then 0 else arr.length
      step = n/(Math.abs n)
      n = Math.abs n
      count = 0
      for i in _.range start, end, step
        break if count > n
        arr[i]++ if arr[i] is val
        count++
      return arr


There was only two ways I could think of to do this without the double reverse.

One would introduce more complex branches (looping backwards in CoffeeScript ain't easy) and the other would be using Underscore.js's range function to do the same thing - that solution would be basically identical to this, except without the reverses, only I'd consider that cheating.


People are just lazy since it usually doesn't matter.

array[i]++ for i in [-1..-array.length]


Keynote's just the state of the art in Powerpoint presentations

You know Microsoft succeeded when Powerpoint has become so generic that Keynote is described as being for "Powerpoint presentations".


To be honest, I didn't get the "principled" impression out of anything written here - I think the author was just trying to soften the blow a little bit...


The article does not point out that sampling quora users might not be (I would say is probably not) an unbiased estimator of the the students of these places as a whole.

From the article:

Also, a word of warning: my dataset was fairly small and users on Quora are almost certainly not representative of their schools as a whole (though I tried to be rigorous with what I had).


I completely missed that, mea culpa, my apologies to the author. I'll leave the message above unedited as a little warning sign to other people who can't read: you too can look silly like me.


Amerteurish would be to blindly carry on launching a product and then releaseing version 2.0 that fixed all the issues and making the 1.0 unsuported.

Sounds like Google TV...


Google TV's lack of success has certainly taught them a lesson or two here. Hence, the freebies as an attempt to win back good will.


The lesson they need to learn is don't do things that lose goodwill in the first place.


Yep, because "Samsung" and "Apple" is dangerously close to "Levy's" and "Levi's".


I have to admit, I'd always sort of dismissed "bizdev" and the like, but this summer I'm working for a small, three-person startup that's one developer and two sales/bizdev and it's completely changed my mind - they're absolutely fantastic.


add(foo, bar) isn't any clearer than foo + bar, but usually an overloaded operator doesn't correspond to "add".

For example, in Javascript: "Hello" + " " + "World!". What the operator there is doing is concatenating the strings, so if you had a method to do it you wouldn't call it add - you'd call it concat.


But then you lose the information that both ((usually modular) arithmetic, and strings with concatenation, et al.) are monoids, and have a similar structure, and creating generic functions which might use that symmetry becomes more difficult.


In python you can overload + and a lot of other numeric operators by implementing certain methods __add__ for +, see others here: http://docs.python.org/reference/datamodel.html#emulating-nu...

In ruby you can implement certain numerical methods including +

In smalltalk + is a binary method, you can give your methods all sort of symbol names. Same with Scala I think.


> For example, in Javascript: "Hello" + " " + "World!". What the operator there is doing is concatenating the strings

Hmm, are we talking about (user defined) operator overloading as a language feature, or about overloaded operators? For example, I hate that 1/2 and 1.0/2 are different things in most languages, but I haven't heard anyone call this operator overloading in the context of C.


while 60% of men in start-ups believe diverse teams are better at innovation and problem-solving, only 41% would be in favor of a companywide hiring practice to increase diversity.

Really?

If 60% believed, for example, that knowing how to code made for better hires, would only 41% be in favor of hiring people who know how to code?

Those are... not the same thing at all. That is an extremely flawed analogy.

The survey is taking about what makes for a good TEAM - further, it's only part of what makes a good team - one factor of many. You don't hire a team, however, you hire an individual.

The comparison that she draws is significantly more black and white: "Person A is strictly a better hire than person B, but we're hiring person B."


A lot of the small, new businesses/restaurants in Evanston, IL use Square with an iPad for POS.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: