Javascript JS中带有编码挑战的一些说明/提示
我有一个要提交的挑战(没有自动测试/测试用例-只是一个书面问题)-我不确定我做得是否正确(作为一个noob和所有那些爵士乐) 我需要为呼叫中心编写类和数据结构: 它有3个级别的员工可以接听电话 对于每个来电,系统将检查谁可用-从3个员工级别中的最低级别开始, 然后,如果该级别没有员工可以自由接听电话,则该级别将上升,直到达到第三级 他们没有给我任何其他指示,所以我正在尽力 这就是我到目前为止的代码-我错过了什么/应该更改什么Javascript JS中带有编码挑战的一些说明/提示,javascript,class,data-structures,Javascript,Class,Data Structures,我有一个要提交的挑战(没有自动测试/测试用例-只是一个书面问题)-我不确定我做得是否正确(作为一个noob和所有那些爵士乐) 我需要为呼叫中心编写类和数据结构: 它有3个级别的员工可以接听电话 对于每个来电,系统将检查谁可用-从3个员工级别中的最低级别开始, 然后,如果该级别没有员工可以自由接听电话,则该级别将上升,直到达到第三级 他们没有给我任何其他指示,所以我正在尽力 这就是我到目前为止的代码-我错过了什么/应该更改什么 class CallCenter{ constructor(){
class CallCenter{
constructor(){
if (!CallCenter.instance){
CallCenter.instance = this
this.callsQueue = []
this.employees = []
return this
}
return CallCenter.instance
}
addEmployee(emp){
this.employees.push(emp)
}
addPhoneCall(call){
this.callsQueue.push(call)
}
dispatchCallDirector(call){
const emp = this.employees.find(e => e.type === "director" && e.available)
}
dispatchCallManager(call){
const emp = this.employees.find(e => e.type === "manager" && e.available)
if (emp){
emp.getPhoneCall(call, (res) => {
if (!res){
this.dispatchCallDirector(call)
}
})
}
}
dispatchCall(){
const call = this.callsQueue[0]
this.callsQueue.splice(0, 1)
const emp = this.employees.find(e => e.type === "respondent" && e.available)
if (emp){
emp.getPhoneCall(call, (res) => {
if (!res){
this.dispatchCallManager(call)
}
})
}
}
}
module.exports = CallCenter
class Employee{
constructor(type){
this.available = true
this.type = type
}
set isAvailable(flag){ //available = true or false
this.available = flag
}
get isAvailable() {this.available}
getPhoneCall(call, report){
//if employee cant handle the call -
report(null)
//if employee can handle the call - this.available = false
}
}
module.exports = Employee
get-isAvailable(){this.available}
->get-isAvailable(){return this.available}
dispatchCallDirector(call){const-emp=this.employees.find(e=>e.type==“director”&e.available)}
您对emp
不做任何事情,谢谢您的评论,弗拉兹,实际上,我才刚刚开始构建解决方案,所以我还没有准备好工作部件。get isAvailable(){this.available}
->get isAvailable(){return this.available}
dispatchCallDirector(call){const emp=this.employees.find(e=>e.type==“director”&&e.available)}
你不用emp做任何事
谢谢你的评论VLAZ,我实际上才刚开始构建解决方案-所以我还没有一个合适的工作部件。