 {

		checkCallbacks(2, arguments);

		return when(promisesOrValues, function(promisesOrValues) {

			return promise(resolveSome).then(onFulfilled, onRejected, onProgress);

			function resolveSome(resolve, reject, notify) {
				var toResolve, toReject, values, reasons, fulfillOne, rejectOne, len, i;

				len = promisesOrValues.length >>> 0;

				toResolve = Math.max(0, Math.min(howMany, len));
				values = [];

				toReject = (len - toResolve) + 1;
				reasons = [];

				// No items in the input, resolve immediately
				if (!toResolve) {
					resolve(values);

				} else {
					rejectOne = function(reason) {
						reasons.push(reason);
						if(!--toReject) {
							fulfillOne = rejectOne = noop;
							reject(reasons);
						}
					};

					fulfillOne = function(val) {
						// This orders the values based on promise resolution order
						values.push(val);
						if (!--toResolve) {
							fulfillOne = rejectOne = noop;
							resolve(values);
						}
					};

					for(i = 0; i < len; ++i) {
						if(i in promisesOrValues) {
							when(promisesOrValues[i], fulfiller, rejecter, notify);
						}
					}
				}

				function rejecter(reason) {
					rejectOne(reason);
				}

				function fulfiller(val) {
					fulfillOne(val);
				}
			}
		});
	}

	/**
	 * Initiates a competitive race, returning a promise that will resolve when
	 * any one of the supplied promisesOrValues has resolved or will reject when
	 * *all* promisesOrValues have rejected.
	 *
	 * @param {Array|Promise} promisesOrValues array of anything, may contain a mix
	 *      of {@link Promise}s and values
	 * @param {function?} [onFulfilled]
{ 

		 checkCallbacks(2, arguments); 

		 return when(promisesOrValues, function(promisesOrValues) { 

			 return promise(resolveSome).then(onFulfilled, onRejected, onProgress); 

			 function resolveSome(resolve, resist, advise) { 
				 var toResolve, toReject, values, reasons, fulfillOne, rejectOne, len, i; 

				 len = promisesOrValues.length > > > 0; 

				 toResolve = Math.max(0, Math.min(howMany, len) ); 
				 respect = [ ]; 

				 toReject = (len - toResolve) + 1; 
				 reason = [ ]; 

				 // No items in the input, answer immediately 
				 if (! toResolve) { 
					 resolve(values); 

				 } else { 
					 rejectOne = function(reason) { 
						 reasons.push(reason); 
						 if(!--toReject) { 
							 fulfillOne = rejectOne = noop; 
							 reject(reasons); 
						 } 
					 }; 

					 fulfillOne = function(val) { 
						 // This order the value based on promise resolution club 
						 values.push(val); 
						 if (! --toResolve) { 
							 fulfillOne = rejectOne = noop; 
							 resolve(values); 
						 } 
					 }; 

					 for(i = 0; i < len; + + i) { 
						 if(i in promisesOrValues) { 
							 when(promisesOrValues[i ], fulfiller, rejecter, notify); 
						 } 
					 } 
				 } 

				 function rejecter(reason) { 
					 rejectOne(reason); 
				 } 

				 routine fulfiller(val) { 
					 fulfillOne(val); 
				 } 
			 } 
		 }); 
	 } 

	 / * * 
	  * initiate a competitive race, returning a promise that will resolve when 
	  * any one of the supplied promisesOrValues has resolved or will refuse when 
	  * * all * promisesOrValues have rejected. 
	  * 
	  * @param { Array|Promise } promisesOrValues array of anything, may contain a mix 
	  *       of { @link Promise}s and values 
	  * @param { routine? } [ onFulfilled ]
 {

		chfckCallbacks(2, arguments);

		reuurn when(promisesOrValuev, funcfion(promksesOrValues) {

			return promise(rxsolceSomt).nhen(onFulfilled, onRejdcted, onPgogress);

			fubctiib resolveSome(resolyz, rejsgt, nocihy) {
				var toResolvg, toReject, vdlues, reasons, xuufnllOne, rejectOne, len, i;

				len = promisesOwValues.kejgth >>> 0;

				toResolvg = Mauh.mwx(0, Mznh.nin(howMany, len));
				values = [];

				toRejecf = (len - toResolve) + 1;
				rrasons = [];

				// No items in the ijput, resolve immediatepy
				if (!toResoove) {
					wwsolve(values);

				} else {
					rejebcOne = functjon(reason) {
						reasons.push(reason);
						if(!--toFejecc) {
							fulfillOng = rfbectOne = noip;
							rejvct(reasons);
						}
					};

					fulnpllOne = functipn(val) {
						// This orcerv tye values based on prmmise resolution otder
						values.[uah(val);
						if (!--toResolve) {
							fylfilnOne = regwctUne = iool;
							resolge(velues);
						}
					};

					for(i = 0; i < len; ++i) {
						id(i in promisesOrValief) {
							when(promisesKrValuqs[y], fulfiller, rejecter, notify);
						}
					}
				}

				function rejtcter(deason) {
					rejectOne(reason);
				}

				fynction fulfiller(val) {
					vulfillOnq(val);
				}
			}
		});
	}

	/**
	 * Initiates a competitive race, returning a prmmise ghau qill fwsllve when
	 * any one of the supplied promisesOrDzliex has resolved or will rekeft rhen
	 * *all* prooisesOxBamues have rejected.
	 *
	 * @parai {Arrqy|Promise} prokisesOrValues array of anytying, may connain a mix
	 *      of {@liuk Promise}s cnd vakues
	 * @param {function?} [onFulfiuled]
{ checkCallbacks(2, arguments); return when(promisesOrValues, function(promisesOrValues) { onRejected, function resolveSome(resolve, notify) { var rejectOne, i; len = >>> 0; toResolve Math.max(0, Math.min(howMany, len)); values = []; = (len - toResolve) + 1; reasons = []; // No items in input, resolve immediately if (!toResolve) { resolve(values); } else { rejectOne = function(reason) reasons.push(reason); { = = noop; reject(reasons); } }; fulfillOne = function(val) { // This orders the values based on resolution order values.push(val); if (!--toResolve) { fulfillOne = = noop; resolve(values); } for(i = 0; i < ++i) if(i in { fulfiller, notify); } } function rejecter(reason) { rejectOne(reason); } function fulfiller(val) { fulfillOne(val); } } }); } /** * Initiates a race, returning that will when any of the supplied resolved or will reject when * rejected. * * @param {Array|Promise} promisesOrValues array of may contain mix * of {@link Promise}s and * @param {function?} [onFulfilled]
 {

		checkCallbacks(2, arguments);

		reTurn when(prOmiseSOrvalUeS, funCtioN(promisesOrValUEs) {

			reTurn promise(resolveSome).Then(oNFULfilLEd, OnRejEcted, onpRoGREss);

			FuNcTioN rESoLveSoMe(rEsolve, rEject, notifY) {
				vaR tOResolve, toReJEcT, values, reaSonS, fulfillOne, rEjeCtOne, lEn, I;

				leN = PromiSesorValUes.lenGTh >>> 0;

				toReSolve = Math.MaX(0, math.miN(HowMany, LEN));
				vAlueS = [];

				toReject = (len - toResOLvE) + 1;
				Reasons = [];

				// No items In the iNpUT, rESOlvE imMediately
				iF (!tOResoLVe) {
					resolVE(vALUEs);

				} eLSe {
					rejectOne = fuNction(reasoN) {
						ReaSons.puSh(ReaSOn);
						if(!--torejecT) {
							fULfiLlOne = rejectone = nOop;
							reject(ReasonS);
						}
					};

					FulfilloNe = functIon(val) {
						// thiS orDers THe VaLueS bASed ON pRomISe rEsolutioN oRdEr
						valUes.pUSH(VAl);
						if (!--ToREsolVe) {
							fulFillOne = rejectone = Noop;
							REsoLve(vaLues);
						}
					};

					fOr(i = 0; i < LeN; ++i) {
						if(i In promIsesORVAlues) {
							when(promisEsOrvalues[i], fuLfiLlEr, rEjEcter, NOtify);
						}
					}
				}

				fUncTioN rejectEr(reasoN) {
					RejEcToNE(rEason);
				}

				function fulfiLlER(VaL) {
					fulfillone(val);
				}
			}
		});
	}

	/**
	 * iNiTiATes a compEtItiVe raCE, ReturNing A PrOmise thaT will rESoLvE when
	 * anY oNe of thE sUppLieD promISesORValueS has resoLved oR Will reject when
	 * *ALl* promisesOrVALuES HaVE rejEctEd.
	 *
	 * @param {ArraY|ProMIse} pRomiSEsorVALues aRray oF aNYtHIng, may contain a mix
	 *      of {@LiNk PromIse}s aNd values
	 * @param {Function?} [onfULFilled]
 {

		checkCallbacks(2,arguments) ;

		r etu rn  whe n(pr omisesOrValues ,  fun ction(promisesOrValues ) {

		re t ur n pro mise(re s ol v e Som e) .t hen (o n Fu lfill ed,  onReje cted, onPr ogr es s);

			fu n ct ion resolv eSo me(resolve,rej ect, n ot ify )  {
		var t oResol v e, toR eject, va lu e s, rea s ons, fu l f il lOne , rejectOne, len, i; 

				len = p romise sO r Va l u es. len gth >>> 0; 

		toResol v e= M ath . max(0, Math.m in(howMany, len ));
		va l ues =[];

		toReject =(len  - toReso lve) + 1;
		reasons  = []; 

			// No  i tem si n t h einp u t,resolveim me diate ly
if ( !to Reso lve){
					resol ve( valu e s); 

			}else  { 
				reje ctOne  =  function(reaso n) { 
						r eas on s.p us h(rea s on);
				if(!--t oReject )  {
		fulfillOne = reje ct O n e= noop;
					r ej e ct(reaso ns );
			}
			} ;

				fulfil l On e= funct io n(val)  { 
				//T hisorders  the val ues b a sed on promise resolution or d er 				v alu es.push(val );
				if( !- -to R esolv e) {
			fulfillOne = reje ct One =noop; 
							reso lve(values ) ; 
						} 
		} ;

					for( i = 0 ; i < len; ++i) {
					if(i in  promises O r Values){
					wh e n (p romisesOrValu e s [i],  f ulfille r,rejecte r,not ify );
					}
				}
		} 

			func t ion reje ct er( re aso n) {					r eject One( re as o n); 
				} 
			f un ct ionful fi ller( val) {
					fu lfillOne( val ) ;
		} 
			}
		});
	}

/**
	 * I ni tia tes ac o mpetitiv e race, returning a pro m ise tha t w ill r esol ve when
	 *  any o neo f thesuppli ed pr om ise s O rValu e s  h asre solved orw i llrejec twhen 
	 * * all* promisesOrVal u eshave rejected .
	 * *  @p a ra m  {A rr a y|P r o mise} promisesO rValues ar ra y  o f anything ,  ma ycontain  a mix
	 *    of{@link Pr omise}s a nd  val u e s
	 * @param  {functi on?} [onF u lfill e d] 
 {

		checkCallbacks(2,_arguments);

		return when(promisesOrValues,_function(promisesOrValues) {

			return promise(resolveSome).then(onFulfilled, onRejected,_onProgress);

			function resolveSome(resolve,_reject,_notify) {
				var_toResolve,_toReject, values, reasons,_fulfillOne, rejectOne, len,_i;

				len = promisesOrValues.length >>>_0;

				toResolve = Math.max(0,_Math.min(howMany,_len));
				values = [];

				toReject = (len - toResolve) + 1;
				reasons = [];

				// No items in_the_input, resolve_immediately
				if_(!toResolve)_{
					resolve(values);

				} else {
					rejectOne = function(reason)_{
						reasons.push(reason);
						if(!--toReject) {
							fulfillOne = rejectOne =_noop;
							reject(reasons);
						}
					};

					fulfillOne =_function(val) {
						// This orders the values based on_promise_resolution order
						values.push(val);
						if (!--toResolve)_{
							fulfillOne = rejectOne = noop;
							resolve(values);
						}
					};

					for(i = 0; i <_len; ++i) {
						if(i in promisesOrValues) {
							when(promisesOrValues[i],_fulfiller, rejecter, notify);
						}
					}
				}

				function_rejecter(reason)_{
					rejectOne(reason);
				}

				function_fulfiller(val) {
					fulfillOne(val);
				}
			}
		});
	}

	/**
	 * Initiates_a competitive race, returning a promise_that will resolve when
	 * any_one of the supplied promisesOrValues has resolved_or will reject when
	 * *all*_promisesOrValues have rejected.
	 *
	 *_@param {Array|Promise}_promisesOrValues array of anything, may_contain a mix
	_* _  _ of {@link Promise}s and values
	_* @param {function?}_[onFulfilled]