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
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.
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.
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.
> 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."