This new version does compare id properties. I don't think you can avoid the
This new version does compare id properties. I don't think you can avoid thegetIds()
step anyway, which is why it wasn't in the previous version.getIds()
step anyway, which is why it wasn't in the previous version.b being longer than a wasn't a problem. b being shorter than a could have been one: with
b being longer than a wasn't a problem. b being shorter than a could have been one: witha = [undefined]
,a[20] == a[0]
is true. UsingindexOf
to search elements means I no longer have to deal with that.a = [undefined]
,a[20] == a[0]
is true. UsingindexOf
to search elements means I no longer have to deal with that.There is no duplication since ids are unique.
There is no duplication since ids are unique.I switched to
every()
, which does the same thing that my previousreduce()
implementation, but is way simpler.function areDifferentByIds(a, b) { var idsA = getIds(a); var idsB = getIds(b);
return a.every(function(e, i) { return b.indexOf(e) == i }
}
I switched toevery()
, which does the same thing that my previousreduce()
implementation, but is way simpler.
The code:
function areDifferentByIds(a, b) {
var idsA = getIds(a);
var idsB = getIds(b);
return a.every(function(e, i) { return b.indexOf(e) == i }
}