With the following JavaScript, why does the output contain multiple copies of the same value?
reduce = function(docs) {
var values = [];
docs.forEach(function(doc) {
if (values.indexOf(doc.value) != -1) return;
values.push(doc.value.toDateString());
});
return values;
}
doc = {value: new Date("2012-01-01T00:00:00Z")}
reduce( [ doc, doc ] )
// => ["Sat Dec 31 2011", "Sat Dec 31 2011"]
Your verfication is wrong.
It should be
if (values.indexOf(doc.value.toDateString()) != -1) return;