function _sortItems(sTextToFilter, aItems, vTextGetter) {
		return aItems
			.map(function (oItem) {
				return [oItem, _extractTextsFromItem(oItem, vTextGetter)];
			})
			.sort(function (aLeftItemMeta, aRightItemMeta) {
				var bLeft, bRight,
					aLeftTexts = aLeftItemMeta[1],
					aRightTexts = aRightItemMeta[1];

				for (var i = 0; i < aLeftTexts.length; i++) {
					bLeft = _startsWithIgnoreCase(aLeftTexts[i], sTextToFilter);
					bRight = _startsWithIgnoreCase(aRightTexts[i], sTextToFilter);

					if (bLeft && bRight) {
						return 0;
					} else if (_startsWithIgnoreCase(aLeftTexts[i], sTextToFilter)) {
						return -1;
					} else if (_startsWithIgnoreCase(aRightTexts[i], sTextToFilter)) {
						return 1;
					}
				}

				return 0;
			})
			// Normalize the output result
			.map(function (aItemMeta) { return aItemMeta[0]; });
	}
/**
	 * Sorts items based on the best match. The first item is most likely to be the selected one.
	 *
	 * Items could have multiple texts and the sorting criteria is:
	 * - the matching text with lower index in the array gets a higher priority
	 * For example, if there's an array of texts: left: ["bar", "foo"], right: ["foo", "bar"] and the search is "fo",
	 * the order would be:
	 * 1. ["foo", "bar"]
	 * 2. ["bar", "foo"]
	 *
	 * @param sTextToFilter {string}
	 * @param aItems {array<T>}
	 * @param vTextGetter {string|function}
	 * @returns {array<T>}
	 * @private
	 */
Sorts items based on the best match. The first item is most likely to be the selected one.


Sorts items based on the best match . The first item is most likely to be the selected one .
function _sortItems(sTextToFilter, aItems, vTextGetter) {
		return aItems
			.map(function (oItem) {
				return [oItem, _extractTextsFromItem(oItem, vTextGetter)];
			})
			.sort(function (aLeftItemMeta, aRightItemMeta) {
				var bLeft, bRight,
					aLeftTexts = aLeftItemMeta[1],
					aRightTexts = aRightItemMeta[1];
				for (var i = 0; i < aLeftTexts.length; i++) {
					bLeft = _startsWithIgnoreCase(aLeftTexts[i], sTextToFilter);
					bRight = _startsWithIgnoreCase(aRightTexts[i], sTextToFilter);
					if (bLeft && bRight) {
						return 0;
					} else if (_startsWithIgnoreCase(aLeftTexts[i], sTextToFilter)) {
						return -1;
					} else if (_startsWithIgnoreCase(aRightTexts[i], sTextToFilter)) {
						return 1;
					}
				}
				return 0;
			})
			.map(function (aItemMeta) { return aItemMeta[0]; });
	}
function _sortItems ( sTextToFilter , aItems , vTextGetter ) { return aItems . map ( function ( oItem ) { return [ oItem , _extractTextsFromItem ( oItem , vTextGetter ) ] ; } ) . sort ( function ( aLeftItemMeta , aRightItemMeta ) { var bLeft , bRight , aLeftTexts = aLeftItemMeta [ 1 ] , aRightTexts = aRightItemMeta [ 1 ] ; for ( var i = 0 ; i < aLeftTexts . length ; i ++ ) { bLeft = _startsWithIgnoreCase ( aLeftTexts [ i ] , sTextToFilter ) ; bRight = _startsWithIgnoreCase ( aRightTexts [ i ] , sTextToFilter ) ; if ( bLeft && bRight ) { return 0 ; } else if ( _startsWithIgnoreCase ( aLeftTexts [ i ] , sTextToFilter ) ) { return - 1 ; } else if ( _startsWithIgnoreCase ( aRightTexts [ i ] , sTextToFilter ) ) { return 1 ; } } return 0 ; } ) . map ( function ( aItemMeta ) { return aItemMeta [ 0 ] ; } ) ; }
Sorts items based on the best match.
Sorts items based on the best match .
// Normalize the output result