Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 9x 5x 3x 3x 4x 2x | /**
* Collection class prototype that implements a symbolic iterator usable in the CommandProcessor class
*/
class IterableCollection {
/**
* Creates an empty collection with a starting internal index `_i` of 0
*/
constructor () {
this._i = 0
}
/**
* Returns the number of instances in the collection
* @return {number} length
*/
length () {
let l = 0
for (let i = 0; i < this._i; i++) {
if (this.hasOwnProperty(i)) l++
}
return l
}
/**
* Returns the current `_i` value and then increments it
* @return {number} index
*/
getIndex () {
return this._i++
}
/**
* Adds item to the collection. Uses the {@link getIndex}
* method to control the key descriptor. Returns the index
* of the added item.
* @param {any} item
* @return {number} index
*/
add (item) {
const i = this.getIndex()
this[i] = item
return i
}
/**
* This symbolic iterator is what makes this collection unique.
* It is a generator function that yields an object containing
* the index key descriptor and the item
* @method [Symbol.iterator]
* @memberof! IterableCollection#
* @yields {IterableCollectionItem}
*/
* [Symbol.iterator] () {
let i = 0
while (i < this._i) {
Eif (this.hasOwnProperty(i)) yield { i, c: this[i++] }
}
}
/**
* @typedef {Object} IterableCollectionItem
* @property {number} i The index key descriptor of the item
* @property {any} c The item within the collection at the given index
*/
}
module.exports = IterableCollection
|