Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Алфавитная сортировка с разделением в объекты по первой букве
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;
}
@evgenyrodionov
Copy link
Author

evgenyrodionov commented Nov 29, 2013

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

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