function sortItemsByReference(items, refItems) {

    var newItems = [];
    var currentItems = items.concat();
    var item;
    var currentIndex;
    var i;

    for (i = 0; i < refItems.length; i++) {
      item = refItems[i];
      currentIndex = currentItems.indexOf(item);
      if (currentIndex > -1) {
        newItems.push(item);
        currentItems.splice(currentIndex, 1);
      }
    }

    items.splice.apply(items, [0, items.length].concat(newItems).concat(currentItems));

    return items;

  }
/**
   * Reorder an array of items based on another array of items.
   *
   * @private
   * @param {Item[]} items
   * @param {Item[]} refItems
   * @returns {Item[]}
   */
Reorder an array of items based on another array of items.
Reorder an array of items based on another array of items .
function sortItemsByReference(items, refItems) {
    var newItems = [];
    var currentItems = items.concat();
    var item;
    var currentIndex;
    var i;
    for (i = 0; i < refItems.length; i++) {
      item = refItems[i];
      currentIndex = currentItems.indexOf(item);
      if (currentIndex > -1) {
        newItems.push(item);
        currentItems.splice(currentIndex, 1);
      }
    }
    items.splice.apply(items, [0, items.length].concat(newItems).concat(currentItems));
    return items;
  }
function sortItemsByReference ( items , refItems ) { var newItems = [ ] ; var currentItems = items . concat ( ) ; var item ; var currentIndex ; var i ; for ( i = 0 ; i < refItems . length ; i ++ ) { item = refItems [ i ] ; currentIndex = currentItems . indexOf ( item ) ; if ( currentIndex > - 1 ) { newItems . push ( item ) ; currentItems . splice ( currentIndex , 1 ) ; } } items . splice . apply ( items , [ 0 , items . length ] . concat ( newItems ) . concat ( currentItems ) ) ; return items ; }
Reorder an array of items based on another array of items.
Reorder an array of items based on another array of items .