How might I find the largest number contained in a JavaScript array?

I have a simple JavaScript Array object containing a few numbers. [267, 306, 108] Is there a function that would find the largest number in this array? 32 Answers 32 Resig to the rescue: Array.max = function( array ){ return Math.max.apply( Math, array ); }; Warning: since the maximum number of arguments is as low … Read more

An algorithm for inflating/deflating (offsetting, buffering) polygons

How would I “inflate” a polygon? That is, I want to do something similar to this: The requirement is that the new (inflated) polygon’s edges/points are all at the same constant distance from the old (original) polygon’s (on the example picture they are not, since then it would have to use arcs for inflated vertices, … Read more