Last active
July 8, 2016 21:01
-
-
Save cdiaz/56539cde0ccf23db9604abfeebf5d53b 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
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