This is a handy helper for functional sorting of arrays based on their content.
var sortBy = function(a,b,c){c=a.slice();return c.sort(function(d,e){d=b(d),e=b(e);return(d<e?-1:d>e?1:0)})};
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/.
AFAIK, the sort callback need not specifically return -1,0,1, but any Numeral. Therefore, you can shorten your function to
function(a,b,c){c=a.slice();return c.sort(function(d,e){d=b(d),e=b(e);return d-e})};
Btw, nice use of slice :-)
Regards, Alex