![]()
Snippets of A |
|
|
What are snippets? |
|
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
== 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.