Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions chapters/arrays/max-array-value.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
layout: recipe
title: Max Array Value
chapter: Arrays
---

h2. Problem

You need to find the largest value contained in an array

h2. Solution

Use javascript's Math.max, along with a for loop

{% highlight coffeescript %}
max = Math.max(max or= num, num) for num in [12,32,11,67,1,3]
# => 67
{% endhighlight %}

h2. Discussion

or= takes care of the initial assignment