Skip to content

Instantly share code, notes, and snippets.

@cdiaz
Last active July 8, 2016 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdiaz/56539cde0ccf23db9604abfeebf5d53b to your computer and use it in GitHub Desktop.
Save cdiaz/56539cde0ccf23db9604abfeebf5d53b to your computer and use it in GitHub Desktop.
var dictionary = ['miel', 'extraterrestre', 'al', 'automovil', 'auto', 'revestir'];
var alphabet = "zyxwvutsrqponmlkjihgfedcba";
function sort(dictionary, alphabet) {
function translate(str, alphabet) {
var abc = "abcdefghijklmnopqrstuvwxyz";
return [].map.call(str, function(c) {
return alphabet[abc.indexOf(c)] || c;
}).join(" ");
}
return (dictionary.sort(function(a, b) {
return translate(a, alphabet).localeCompare(translate(b, alphabet));
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment