DisplayName Dialog
by Christian Mueller
JavaScript
var items = [
{
"_id": "Fizz"
},
{
"_id": "Frogmorton",
"parent": "The Shire"
},
{
"_id": "Hobbiton",
"parent": "The Shire"
},
{
"_id": "Foobar",
"isParent": true
},
{
"_id": "Foobar Xland",
"parent": "Foobar"
},
{
"_id": "The Shire",
"isParent": true
}
]
var sortedArray = items
.sort(function(first, second) {
if(first.isParent && !second.isParent) {
return -1
}
else if(second.isParent && first._id != second.parent) {
return 0
} else {
return 1
}