underscore.js library
http://documentcloud.github.com/underscore/
by Andy Bulka
HTML
<script src="https://raw.github.com/documentcloud/underscore/master/underscore-min.js"></script>
<p>Check out doco at
<a href="http://documentcloud.github.com/underscore/">here</a>
</p>
<div class="log">
<a href="#" id="clearlog">Clear</a>
<div id="log"></div>
</div>
CSS
.log {margin-bottom:8px;background:BurlyWood;}
JavaScript
function msg(s) {
$('<div/>').append(s).appendTo('#log');
}
$('#clearlog').click(function() {
$("#log").empty();
});
// Code
_.each([1, 2, 3, 55, 66, 100, "woo"], function(num){ msg(num); });
var res = _.sortBy([1, 2, 3, 4, 5, 6],
function(num){ return Math.sin(num); });
msg(res);
_.each(res, function(num){ msg(num); });