function sortByOrder(elements, order, splitBy) {
        var results = [];
        order.forEach (function(name) {
            if (splitBy)
                elements.forEach (function(element) {
                    var parts = element.split(splitBy);
                    var key = parts[1]; // reference keep for sorting
                    if (key == name)
                        results.push(element);
                });
            else
                elements.forEach (function(key) {
                    if (key == name)
                        results.push(name);
                });
        });
        // Append all other entries that ar not defined in order
        elements.forEach(function(element) {
            if (results.indexOf(element) === -1)
                results.push(element);
        });
        return results;
    }
function sortByOrder(elements, order, splitBy) {
        var results = [];
        order.forEach (function(name) {
            if (splitBy)
                elements.forEach (function(element) {
                    var parts = element.split(splitBy);
                    var key = parts[1]; // reference keep for sorting
                    if (key == name)
                        results.push(element);
                });
            else
                elements.forEach (function(key) {
                    if (key == name)
                        results.push(name);
                });
        });
        // Append all other entries that ar not defined in order
        elements.forEach(function(element) {
            if (results.indexOf(element) === -1)
                results.push(element);
        });
        return results;
    }
function sortByOrder ( elements , order , splitBy ) { var results = [ ] ; order . forEach ( function ( name ) { if ( splitBy ) elements . forEach ( function ( element ) { var parts = element . split ( splitBy ) ; var key = parts [ 1 ] ; // reference keep for sorting if ( key == name ) results . push ( element ) ; } ) ; else elements . forEach ( function ( key ) { if ( key == name ) results . push ( name ) ; } ) ; } ) ; // Append all other entries that ar not defined in order elements . forEach ( function ( element ) { if ( results . indexOf ( element ) === - 1 ) results . push ( element ) ; } ) ; return results ; }
Return ordered entries by custom order and append not defined entries to the end.
@param  {String[]} elements
@param  {String[]} order
@param  {String}   splitBy
@return {String[]} Custom ordered list.
Return ordered entries by custom order and append not defined entries to the end .