How many operations are there in a Javascript Array Join
method?
Is it simply one operation, or is the number of operations the same as the number of items in the array?
The reason I ask is because I want to know what is the cheapest way to compare the two arrays below:
var a = ["Apples", "Pears", "Bananas"]
var b = ["Apples", "Oranges", "Bananas"]
Method A
For (var i = 0; i < 2; i++) {
if (a[i] === b[i]) console.log(false);
}
Method B
aa = a.join("&");
bb = b.join("&");
if (aa === bb) console.log(false)
Cheapest way without just writing a === b
, because the point is comparing the values in two different arrays.