Skip to content

Instantly share code, notes, and snippets.

@floydpink
Created December 5, 2012 19:52
Show Gist options
  • Save floydpink/4218910 to your computer and use it in GitHub Desktop.
Save floydpink/4218910 to your computer and use it in GitHub Desktop.
Array.Min, Array.Max and jQuery.map()
<span id="toolbar">
<a title="Link 1" tabindex="-1" href="#"></a>
<a title="Link 1" tabindex="-2" href="#"></a>
</span>
$(function() {
//Thanks to John Resig - http://ejohn.org/blog/fast-javascript-maxmin/
Array.max = function(array) {
return Math.max.apply(Math, array);
};
Array.min = function(array) {
return Math.min.apply(Math, array);
};
// Doing some map and find
//var topToolBar = $(top.document).find('#toolbar');
var someToolBar = $('#toolbar');
var tabIndexArrayObject = someToolBar.find('a').map(function() {
return this.tabIndex;
});
var tabIndexArray = Array.prototype.slice.call(tabIndexArrayObject.get());
var tabIndex = Array.min(tabIndexArray) - 1;
alert(tabIndex);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment