From 21ef4ae1f2b78f89f15f21c30f6410cc98ffc2d2 Mon Sep 17 00:00:00 2001 From: David Moulton Date: Sat, 14 May 2011 14:08:01 -0600 Subject: [PATCH] added max-array-value recipe --- chapters/arrays/max-array-value.textile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 chapters/arrays/max-array-value.textile diff --git a/chapters/arrays/max-array-value.textile b/chapters/arrays/max-array-value.textile new file mode 100644 index 0000000..81905fb --- /dev/null +++ b/chapters/arrays/max-array-value.textile @@ -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