- var data =
[
{
"title": "Артем"
},
{
"title": "Аня"
},
{
"title": "Виталик"
},
{
"title": "Гена"
},
{
"title": "Дима"
},
{
"title": "Вася"
},
{
"title": "Гриша"
},
{
"title": "Андрей"
}
]
mixin sort(data)
- var sort = data.sort(function(a, b) {return a.title.localeCompare(b.title);}); // сортируем по алфавиту
each item in sort
.div= title.charAt(0)
А
А
А
В
В
Г
Г
Д
- var data = [ { "title": "Артем" }, { "title": "Аня" }, { "title": "Виталик" }, { "title": "Гена" }, { "title": "Дима" }, { "title": "Вася" }, { "title": "Гриша" }, { "title": "Андрей" } ]
mixin sort(data)
- var grouped = data.reduce((acc, n) => {
- var name = n.title[0];
- acc[name] = acc[name] || [];
- acc[name].push(n);
- return acc;
- }, {});
each group, name in grouped
div
h3= name
each obj in group
div= obj.title
div
+sort(data)
var cats = {};
var sort = data.sort(function(a, b) {return a.title.localeCompare(b.title);})
sort.forEach(function(val) {
(cats[val.title[0]] = cats[val.title[0]] || []).push(val);
});
each item, letter in cats
h4=letter
each user in item
span=item.title