The Identification Number and Password fields need to be filled in. Moreover, you cannot send messages devoid of contents Adding further data is not allowed because this topic has been closed Print You provided no password: you have to write it in the textfield beside the command delete for the topic you want to delete Are you sure you want to delete this comment? You did not cast a vote. You need to cast a vote by selecting a radio button. Impossible to proceed Provide the project number Insufficient form parameters: you forgot to fill in some field/s
 
member picmember pic
 
Snippets of A
 
info Below you can find the text of the snippet you want to read, and the list of the other snippets by this author if available.
What are snippets?
Share on MySpace

Javascript To Find Identical Entries Present In ALL The Input Arrays

Snippet: Identification Number »   Snippet: Inclusion syntax »
Visitors: 8,765 Tagged by its author as: Programming Javascript Characters (in origin): 2,762 (pages: ~ 1)
Author: Em@il Permalink Cast your vote for this topic Printable version
OBJECTIVE: in Javascript, given a set of input array, find out the entries that are present in all of the input arrays (reporting each instance only once).  
function sharedEntries(arrayList){
//validate:
	if(!arrayList||!arrayList.length){return false;}
	else if(arrayList.length==1){return arrayList};
//initialize:
var associativeOutput=new Object();
var output=new Array(0);
//first check:
for(var a in arrayList[0]){
	for(var b in arrayList[1]){
		if(arrayList[0][a]==arrayList[1][b]){
		output[++output.length-1]=arrayList[0][a];
		associativeOutput[ arrayList[0][a] ]=1;
		};
	}
}
//none since inception (requires entries are present in ALL arrays): exit:
if(!output.length){return new Array(0);};
//run:
if(arrayList.length>2){
	for(
	var a=2/*no need to loop again the already checked first 2 input arrays*/;
	a < arrayList.length;
	a++){
	var aMatch=0;
	var fixOutput=new Array(0);
	var fixAssociative=new Object();
		for(var inside in arrayList[a]){
			if(associativeOutput[ arrayList[a][inside] ]){
			aMatch=1;
				if(!fixAssociative[ arrayList[a][inside] ]){
				fixOutput[++fixOutput.length-1]=arrayList[a][inside];
				};
			fixAssociative[ arrayList[a][inside] ]=1;
			};
		}
	if(!aMatch){return new Array(0);};
	output=fixOutput;
	associativeOutput=fixAssociative;
	}
};
return output;
/*keep this comment to reuse freely:
http://www.fullposter.com/?1 */} 
Remove colors  
INPUTS: an array of arrays. The arrays nested in the nesting array are those that must be checked for shared entries.  
 
RETURNS: simple array, each entry being a shared entry namely an entry that recurs in all the input arrays.  
 
CAVEATS: unlike for instance Php, Javascript does not provide built in methods to find out array differences or similar methods, therefore the Javascript implementation takes a full quadratic shape in the worst case scenario: a loop within a loop.  
In order to somewhat mitigate this, there is in the code a section called "first check": that checks whether a shared (that is, identical) entry can be found by limiting the scan to the first two passed arrays; if no shared entry is found in them, the function exits because the task is to find entries that are common in all the passed input arrays to scan, and if there is none even in the first two passed arrays the test has already failed.  
Identity is checked using the == comparison and not the data type and value comparison === because it's not clear to my eyes whether in javascript the nature of the latter could be, on some platforms, faulty.  
 
A Php implementation of this task can be found on Php To Find Identical Items.
Printable version To exclude hyperlinks from the print, check the checkbox »
Rss

Cast your vote for this topic

To perform this operation it is not necessary to be Full Poster members.
«Negative Positive»
Click here to save your vote (Current average: 0.00, Voters: 0)
Are you the author of this topic and do you want to append quickly more text? click here
Other topics
This subscriber has a blog too: Read the blog: 57 Shoutbox: 103 reviews: 153
Visitors: 8,765
Overall visits to all the topics: 4,965,938
Daily average (Calculated from the website subscription day): 2,061.41
Optional sorting commands:
Normal order: click here
Order by amount of visits: click here
Order by category: Programming Javascript
Current order: by category: Programming Ajax
Other categories available for this author (Limited data report: 100):
Advice: Martial Arts and Self Defense(4), Books(236), Critical Reviews and Essays(4), Dictionaries(1), Emergency Care(4), Epistles Letters and Advice(5), Fantasy Epics and Fables(1), History and Documents(5), Humor and Jokes(2), Methematics(2), Music and Lyrics(6), News Digests and Press Reviews(1), Novels Poetry and Stories(3), Philosophy Reviews(7), Poetry(1), Programming(4), Programming Ajax(2), Programming Javascript(82), Programming Php(52), Psychology(1), Quotes(1), Religion Esoterica and Spirituality(12), Scientifical Reviews(4), Self Improvement(1), Sport Activities and Apparels(2), Tarots(1)
Showing topics: 1, 10
Available total: 448
View only a list of the snippets by this author: click here.
Other topics available for this author: click on any title below to view the complete item:
Javascript Ajax: Simple Copy & Paste Ajax Post Get Implementation For Beginners Identification Number: 420 Visitors: 11,309 Ajax Class Script: Javascript Closures For Totally Encapsulated Multi Ajax Class Identification Number: 23 Visitors: 13,369
External services
This page of this subscriber uses external services: Hide