function GroceryList(items){ this.items = items; this.mapItems = (fn) => { let newItems = []; // could use map but it would not fit for this example for (let i = 0; i < this.items.length ; i++){ newItems = [...newItems, fn(this.items[i])]; } this.items = newItems; return this; } return this; }