playing with Set
by Gerald Gillespie
JavaScript
console.clear();
class SubSessionArray {
constructor(values) {
this.collection = new Set();
let keepTrack = this.collection.values()
values.forEach( value =>{
this.collection.add(value);
console.log( keepTrack.next().value);
})
keepTrack = this.collection.values()
values.forEach( value =>{
console.log( keepTrack.next().value);
})
this.current = undefined;
Object.defineProperties(this, {
'length': {
enumerable: true,
get: () => (this.collection.size)
},
'beginning': {
}
});
}
getKeys() {
return [...this.collection]
}
setValue() {
}
getValue({
sourceid
}) {
}
//emulate Netsuite's each iterator
each(callback) {
let _iterable = this.collection.values();
let i = 0;
let x = true;
const looper = ( )=>{
let next = _iterable.next().value;
x= callback(next, i++);
if( x && i < this.collection.size)
looper();
};
looper();
}
} //class
const mySSA = new SubSessionArray([1,2,3,10,'hi']);
mySSA.each( (ssa,i,a)=>{
console.log(ssa);
return true;
})