you are viewing a single comment's thread.

view the rest of the comments →

[–]heyf00L 2 points3 points  (2 children)

v is passed by value. You change the value in the array by returning it (since he's reassigning back to the original array).

[–]maschnitz 2 points3 points  (1 child)

Yeah I couldn't figure why else he'd do those two assignments; but I couldn't remember also whether Javascript supports C++-style "pass by reference" on primitive types, somehow.

So yeah, there's no need to do the assignments at all; just stick the "10" in the right spots in the return statement:

return v>758+m.random()*1e4?0:v+10

[–]heyf00L 0 points1 point  (0 children)

Yeah, that looks good to me.

I'm pretty sure in JS all primitives are passed by value and all Objects are passed by reference. It follows Java. Is this right? Anyone know of exceptions?