Revision: 23516
Updated Code
at February 8, 2010 19:35 by prudnikov
Updated Code
var listsEqual = function(list1, list2){ var differences = 0; // check if all elements from first list exists in the second for(var i=0; i<list1.length;i++){ var exists = false; for(var j=0; j<list2.length; j++){ if(list1[i] == list2[j]){ exists = true; break; } } if(!exists){ differences++; break; } } // and vice versa if(differences == 0){ for(var i=0; i<list2.length;i++){ var exists = false; for(var j=0; j<list1.length; j++){ if(list2[i] == list1[j]){ exists = true; break; } } if(!exists){ differences++; break; } } } return differences == 0; }
Revision: 23515
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 8, 2010 19:33 by prudnikov
Initial Code
var listsEqual = function(list1, list2){ var differences = 0; // check if all elements from first list exists in the second for(var i=0; i<list1.length;i++){ var exists = false; for(var j=0; j<list2.length; j++){ if(list1[i] == list2[j]){ exists = true; break; } } if(!exists){ differences++; break; } } // and vice versa if(differences == 0){ for(var i=0; i<list2.length;i++){ var exists = false; for(var j=0; j<list1.length; j++){ if(list2[i] == list1[j]){ exists = true; break; } } if(!exists){ differences++; break; } } } return differences == 0; }
Initial URL
Initial Description
listsEqual(["1","2"], ["1","2"]) is true;
Initial Title
Verify if content of 2 lists/arrays are eaqual
Initial Tags
javascript, list, array
Initial Language
JavaScript