class SortedSet { constructor() { this.length = 0; } add(element) { p = this.length; for (i = 0; i < this.length; i++) { if (this[i] == element) { return; } else if (this[i] > element) { p = i; break; } } for (i = this.length; i > p; i--) { this[i] = this[i - 1]; } this[p] = element; this.length++; } } class QuantityData { constructor() { this.map = {}; } get(user, code) { if (!(user in this.map) || !(code in this.map[user])) { return 0; } return this.map[user][code]; } set(user, code, quantity) { if (!(user in this.map)) { this.map[user] = {}; } this.map[user][code] = quantity; } } users = new SortedSet(); codes = new SortedSet(); data = new QuantityData(); for (y = 1; y <= Bottom; y++) { users.add([1,y]); codes.add([2,y]); data.set([1,y], [2,y], [3,y]); } DeleteRow(1, Bottom); y = 1; for (user of users) { [1,y] = user; x = 2; for (code of codes) { [x,y] = code; [x+1,y] = data.get(user, code); x += 2; } y++; }