Skip to content

Instantly share code, notes, and snippets.

@imevro
Last active December 15, 2015 13:58
Show Gist options
  • Save imevro/5271006 to your computer and use it in GitHub Desktop.
Save imevro/5271006 to your computer and use it in GitHub Desktop.
Алфавитная сортировка с разделением в объекты по первой букве
function sortByLetter( array ) {
var length = array.length,
groups = {},
item,
firstChar;
for ( var i = 0; i < length; i ++ ) {
item = array[ i ],
firstChar = item.charAt( 0 );
groups[ firstChar ] = groups[ firstChar ] || [];
groups[ firstChar ].push( item );
}
return groups;
}
@imevro
Copy link
Author

imevro commented Nov 29, 2013

Обновил для лучшей производительности.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment