Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    \$\begingroup\$ You can save a bit by only dividing by 2 once. And you don't actually gain anything by assigning to variables: (a=v[0])a is longer than v[0]v[0]. \$\endgroup\$ Commented Mar 27, 2013 at 10:43
  • \$\begingroup\$ If I divided by 2 only one time, like s=(v[0]+v[1]+v[2])/2 with a,b,c=3,4,5 would result in "345"/2=172.5" and not 6. Improved without a, b` and c though. \$\endgroup\$ Commented Mar 27, 2013 at 16:32
  • \$\begingroup\$ Ah, JavaScript's wonderful type system. Ok, s=(-v[0]-v[1]-v[2])/2 and change the other - to +. It's an even number of terms, so it cancels out. \$\endgroup\$ Commented Mar 27, 2013 at 16:39