Created
December 5, 2012 19:52
-
-
Save floydpink/4218910 to your computer and use it in GitHub Desktop.
Array.Min, Array.Max and jQuery.map()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span id="toolbar"> | |
<a title="Link 1" tabindex="-1" href="#"></a> | |
<a title="Link 1" tabindex="-2" href="#"></a> | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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