Test name | Executions per second |
---|---|
Array.every => Array.includes | 46419228.0 Ops/sec |
Array.every => Set.has | 34525136.0 Ops/sec |
var object = {
items: Array.from({
length: 100
}, (_, i) => ({
id: i,
name: `Item-${i}`,
}))
};
// Randomly select ~75% of items
var selectedItems = object.items
.filter(() => Math.random() > 0.25)
.map(item => item.id);
var set = new Set(selectedItems);
return object.items.every(({ id }) => selectedItems.includes(id));
return object.items.every(({ id }) => set.has(id))