Skip to content

Instantly share code, notes, and snippets.

@anler
Last active February 1, 2017 09:23
Show Gist options
  • Save anler/202cfe9d6efd107a350356d1423acce4 to your computer and use it in GitHub Desktop.
Save anler/202cfe9d6efd107a350356d1423acce4 to your computer and use it in GitHub Desktop.
function namesSorter (departmentsArray) {
return sort(
concat(departmentsArray),
byLengthAndAlphabetically
);
}
function concat(xs) { return xs.reduce(concat2, []); }
function concat2(a, b) { return a.concat(b); }
function byLengthAndAlphabetically(x, y) {
var xl = x.length;
var yl = y.length;
if (xl == yl)
return x.localeCompare(y);
else
return xl - yl;
}
function sort(xs, comparator) {
return xs.sort(byLengthAndAlphabetically);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment