Skip to content

Commit

Permalink
Update Pre-ES5 example
Browse files Browse the repository at this point in the history
  • Loading branch information
fhemberger committed Feb 23, 2012
1 parent b81f32e commit 1afb13b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions chapters/arrays/max-array-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ You need to find the largest value contained in an array.

## Solution

In ECMAScript 5, use `Array#reduce`. In older javascripts, use Math.max:
In ECMAScript 5, you can use `Array#reduce`. For compatibility with older javascripts, use Math.max.apply:

{% highlight coffeescript %}
# ECMAScript 5
[12,32,11,67,1,3].reduce (a,b) -> Math.max a, b
# => 67

# Pre-EC5
max = Math.max.apply(null, [12,32,11,67,1,3])
# => [ 12, 32, 32, 67, 67, 67 ]
max
# Pre-ES5
Math.max.apply(null, [12,32,11,67,1,3])
# => 67
{% endhighlight %}

Expand Down

0 comments on commit 1afb13b

Please sign in to comment.