First of all, I've checked similar topics on SO such as this one: Comparing similar strings in jquery But they didn't help.
Here's my code:
//jQuery functions
(function($)
{
arrayToString = function(array)
{
var s = "";
var a = [];
$.each(array, function(i, el){
if($.inArray(el, a) === -1)
{
a.push(el);
if (s!="")
{
s += "@~@~@";
}
s += el;
}
});
return s;
};
})(jQuery);
(function($)
{
intersectionOfArrays = function(a,b)
{
var array = [];
$.each(a, function(i, el){
if($.inArray(el, array) === -1 && $.inArray(el, b) != -1) array.push(el);
});
return array;
};
})(jQuery);
var intersection = arrayToString(intersectionOfArrays(selectionOf("produitcartesien").split("@~@~@"),tripletsOfCollection.split("@~@~@")));
alert("intersection = '"+intersectionOfArrays(selectionOf("produitcartesien").split("@~@~@"),tripletsOfCollection.split("@~@~@"))+"'");
alert("selectionOf(produitcartesien) = '"+selectionOf("produitcartesien")+"'");
alert("They are different: '"+intersection!=selectionOf("produitcartesien")+"'");
Although the alerts sometimes display the same string, the comparison using != and !== always returns true !?
I tried using some other things that I don't remember, but none worked. How can I modify the above code to get the correct answer?
Thank you in advance.