Home > coffeescript, Programming > Array min, max with Coffeescript

Array min, max with Coffeescript

Quite simple actually:


Array::max=->
  Math.max.apply(null, this)

Array::min=->
  Math.min.apply(null, this)

a=[6, 5, 17, -3, 4.5]
console.log a.max()
console.log a.min()

Outputs:
17
-3

Advertisements
Categories: coffeescript, Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: