This is a handy helper for functional sorting of arrays based on their content.
var sortBy = function(a,b){return a.slice().sort(function(c,d){return b(c)-b(d)})}
sortBy(['Fuchs','Diaz','Schmidt'], function(name){ return name.length })
// => ["Diaz", "Fuchs", "Schmidt"]
sortBy([1,2,3], Math.random)
// => [3,1,2]
It's an implementation of Ruby's Enumberable#sort_by functionality, see http://www.ruby-doc.org/core/classes/Enumerable.html#M001481 for more info.
A similiar implementation is available in Prototype.js, as Enumerables, see http://api.prototypejs.org/language/Enumerable/prototype/sortBy/.