โจBag
keeps track of items and its count.
Last updated
Was this helpful?
keeps track of items and its count.
Last updated
Was this helpful?
Was this helpful?
JS โฉ value โฉ object โฉ class โฉ example โฉ Bag
create a new class not by subclassing, but instead by wrapping or โcomposingโ other classes, this delegation approach is often called โcompositionโ.
// โญ๏ธ Bag
// ------------------------------------------------
// create new class by delegation ("composition")
// ------------------------------------------------
// โข .totalCount : total items count
// โข .items : all (different) items (iterator)
// โข .counts : all counts (iterator)
// โข .entries : all item/count pairs (iterator)
// ------------------------------------------------
// โข .count(item): item count
// โข .has(item) : check if bag has item.
// โข .put(item, [count]) : put item in bag.