Last active
February 1, 2017 09:23
-
-
Save anler/202cfe9d6efd107a350356d1423acce4 to your computer and use it in GitHub Desktop.
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 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