lib/polymorphic.js
function matchSignature(list, arg) {
		var types = arg.map(function(variable) {
				return new RegExp('^(' + type(variable) + ')');
			});

		return list.filter(function(config) {
			var variadic = false,
				result;

			//  result is true if no more arguments are provided than the signature allows OR the last
			//  argument in the signature is variadic
			result = arg.length <= config.arguments.length || (config.arguments[config.arguments.length - 1] && config.arguments[config.arguments.length - 1].type === '...');

			//  test each given argument agains the configured signatures
			if (result) {
				arg.forEach(function(value, index) {
					var expect = config.arguments[index] ? config.arguments[index].type : null;

					//  look at ourself and ahead - if there is a following item, and it is variadic, it may be
					//  left out entirely (zero or more)
					if (isTypeAtIndex('...', config.arguments, index)) {
						variadic = true;
					}

					//  the result remains valid as long as the values match the given signature
					//  (type matches or it is variadic)
					result = result && (variadic || types[index].test(expect) || (expect[expect.length - 1] !== '!' && isExtendOf(expect, value)));
				});
			}

			return result;
		});
	}
function matchSignature(list, arg) {
		var types = arg.map(function(variable) {
				return new RegExp('^(' + type(variable) + ')');
			});

		return list.filter(function(config) {
			var variadic = false,
				result;

			//  result is true if no more arguments are provided than the signature allows OR the last
			//  argument in the signature is variadic
			result = arg.length <= config.arguments.length || (config.arguments[config.arguments.length - 1] && config.arguments[config.arguments.length - 1].type === '...');

			//  test each given argument agains the configured signatures
			if (result) {
				arg.forEach(function(value, index) {
					var expect = config.arguments[index] ? config.arguments[index].type : null;

					//  look at ourself and ahead - if there is a following item, and it is variadic, it may be
					//  left out entirely (zero or more)
					if (isTypeAtIndex('...', config.arguments, index)) {
						variadic = true;
					}

					//  the result remains valid as long as the values match the given signature
					//  (type matches or it is variadic)
					result = result && (variadic || types[index].test(expect) || (expect[expect.length - 1] !== '!' && isExtendOf(expect, value)));
				});
			}

			return result;
		});
	}
function matchSignature ( list , arg ) { var types = arg . map ( function ( variable ) { return new RegExp ( '^(' + type ( variable ) + ')' ) ; } ) ; return list . filter ( function ( config ) { var variadic = false , result ; //  result is true if no more arguments are provided than the signature allows OR the last //  argument in the signature is variadic result = arg . length <= config . arguments . length || ( config . arguments [ config . arguments . length - 1 ] && config . arguments [ config . arguments . length - 1 ] . type === '...' ) ; //  test each given argument agains the configured signatures if ( result ) { arg . forEach ( function ( value , index ) { var expect = config . arguments [ index ] ? config . arguments [ index ] . type : null ; //  look at ourself and ahead - if there is a following item, and it is variadic, it may be //  left out entirely (zero or more) if ( isTypeAtIndex ( '...' , config . arguments , index ) ) { variadic = true ; } //  the result remains valid as long as the values match the given signature //  (type matches or it is variadic) result = result && ( variadic || types [ index ] . test ( expect ) || ( expect [ expect . length - 1 ] !== '!' && isExtendOf ( expect , value ) ) ) ; } ) ; } return result ; } ) ; }
Filter given list so only matching signatures are kept
@name    matchSignature
@access  internal
@param   array  candidates
@param   array  arguments
@return  array  filtered candidates
Filter given list so only matching signatures are kept