src/jslinq.js
function subtract(otherData, compareExpression) {
	
		//If other data is invalid, return empty array
        if (!otherData)
            return new jslinq([]);
			
        //Data for output
        var outData = [];

        //Check every element of "items"
        for (var n = 0; n < this.items.length; n++) {
		
			//Current element on items
			var currentOnItems = this.items[n];
			
			//Set flag of "found match" as false
			var aMatchWasFound = false;
		
			//Check every element on "otherData"
			for (var i = 0; i < otherData.length; i++) {
			
				//If a match was already found, skip
				if (aMatchWasFound)
					continue;
			
				//Current element on "otherData"
				var currentOnOtherData = otherData[i];
				
				//Fails by default matching of elements
				var doesMatch = false;
			
				//If compare expression was not set
				if (!compareExpression){
				
					//Compare on same instance
					//doesMatch = currentOnItems == currentOnOtherData;
					doesMatch = equals(currentOnItems, currentOnOtherData);					
				}
				else{
				
					//Calculate comparison value for each element
					var comparisonForItems = compareExpression(currentOnItems);
					var comparisonForOtherData = compareExpression(currentOnOtherData);
				
					//Compare result of compare expressions
					//doesMatch = comparisonForItems == comparisonForOtherData;
					doesMatch = equals(comparisonForItems, comparisonForOtherData);
				}
				
				//If there's a match, set the flag
				if (doesMatch){
					aMatchWasFound = true;
				}				
			}
			
			//If no match was found, append element to output
			if (!aMatchWasFound){
				outData.push(currentOnItems);
			}
        }

        //Return for chaining
        return new jslinq(outData);        
    }
function subtract(otherData, compareExpression) {
	
		//If other data is invalid, return empty array
        if (!otherData)
            return new jslinq([]);
			
        //Data for output
        var outData = [];

        //Check every element of "items"
        for (var n = 0; n < this.items.length; n++) {
		
			//Current element on items
			var currentOnItems = this.items[n];
			
			//Set flag of "found match" as false
			var aMatchWasFound = false;
		
			//Check every element on "otherData"
			for (var i = 0; i < otherData.length; i++) {
			
				//If a match was already found, skip
				if (aMatchWasFound)
					continue;
			
				//Current element on "otherData"
				var currentOnOtherData = otherData[i];
				
				//Fails by default matching of elements
				var doesMatch = false;
			
				//If compare expression was not set
				if (!compareExpression){
				
					//Compare on same instance
					//doesMatch = currentOnItems == currentOnOtherData;
					doesMatch = equals(currentOnItems, currentOnOtherData);					
				}
				else{
				
					//Calculate comparison value for each element
					var comparisonForItems = compareExpression(currentOnItems);
					var comparisonForOtherData = compareExpression(currentOnOtherData);
				
					//Compare result of compare expressions
					//doesMatch = comparisonForItems == comparisonForOtherData;
					doesMatch = equals(comparisonForItems, comparisonForOtherData);
				}
				
				//If there's a match, set the flag
				if (doesMatch){
					aMatchWasFound = true;
				}				
			}
			
			//If no match was found, append element to output
			if (!aMatchWasFound){
				outData.push(currentOnItems);
			}
        }

        //Return for chaining
        return new jslinq(outData);        
    }
function subtract ( otherData , compareExpression ) { //If other data is invalid, return empty array if ( ! otherData ) return new jslinq ( [ ] ) ; //Data for output var outData = [ ] ; //Check every element of "items" for ( var n = 0 ; n < this . items . length ; n ++ ) { //Current element on items var currentOnItems = this . items [ n ] ; //Set flag of "found match" as false var aMatchWasFound = false ; //Check every element on "otherData" for ( var i = 0 ; i < otherData . length ; i ++ ) { //If a match was already found, skip if ( aMatchWasFound ) continue ; //Current element on "otherData" var currentOnOtherData = otherData [ i ] ; //Fails by default matching of elements var doesMatch = false ; //If compare expression was not set if ( ! compareExpression ) { //Compare on same instance //doesMatch = currentOnItems == currentOnOtherData; doesMatch = equals ( currentOnItems , currentOnOtherData ) ; } else { //Calculate comparison value for each element var comparisonForItems = compareExpression ( currentOnItems ) ; var comparisonForOtherData = compareExpression ( currentOnOtherData ) ; //Compare result of compare expressions //doesMatch = comparisonForItems == comparisonForOtherData; doesMatch = equals ( comparisonForItems , comparisonForOtherData ) ; } //If there's a match, set the flag if ( doesMatch ) { aMatchWasFound = true ; } } //If no match was found, append element to output if ( ! aMatchWasFound ) { outData . push ( currentOnItems ) ; } } //Return for chaining return new jslinq ( outData ) ; }
Get only elements NOT contained on provided "otherData" using same instance or compare expression
Get only elements NOT contained on provided otherData using same instance or compare expression