/
CallCue.js
35 lines (33 loc) · 930 Bytes
/
CallCue.js
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
function CallCue()
{
this.cues = [
{floor: 7, direction: DOWN},
{floor: 2, direction: UP},
{floor:10, direction: DOWN},
{floor: 0, direction: UP},
{floor: 9, direction: DOWN},
{floor: 9, direction: UP},
{floor: 9, direction: IDLE},
{floor: 7, direction: UP}
],
this.add = function(floor, direction){
// if floor not exist, add it
var obj = {
floor: floor,
direction: direction
};
if(this.cues.every(
function(el,index,arr){
return el.floor !== floor || el.direction !== direction
})){
this.cues.push(obj);
}
},
this.delete = function(floor){
// delete floor from cue
while(deleteMe = this.cues.find(floor)){
this.cues.splice(deleteMe[0],1);
console.log("deleting floor "+floor);
}
}
}