In this scenario, I have an array that needs to be checked for any AvgWT
value.
- If the value is greater than 15000 and less than 20000, then return 50.
- If the value is greater than 10000 and less than 15000, then return 100.
- If the value is greater than 5000 and less than 10000, then return 150.
I attempted the following code.
var data = [{"TimeSlot":"8:00 am","AssistedC":0,"Abandons":0,"AvgWT":12152},{"TimeSlot":"8:15 am","AssistedC":0,"Abandons":0,"AvgWT":13942},{"TimeSlot":"8:30 am","AssistedC":0,"Abandons":0,"AvgWT":0},{"TimeSlot":"8:45 am","AssistedC":0,"Abandons":0,"AvgWT":0},{"TimeSlot":"9:00 am","AssistedC":0,"Abandons":0,"AvgWT":0},{"TimeSlot":"9:15 am","AssistedC":0,"Abandons":0,"AvgWT":0},{"TimeSlot":"6:30 pm","AssistedC":0,"Abandons":0,"AvgWT":0},{"TimeSlot":"6:45 pm","AssistedC":0,"Abandons":0,"AvgWT":0},{"TimeSlot":"7:00 pm","AssistedC":0,"Abandons":0,"AvgWT":0}];
function checkArrayValues(data) {
// var first = array[0];
var first = data[0]["AvgWaitTime"];
return data.every(function(element) {
if(element["AvgWaitTime"] > 15000 && element["AvgWaitTime"] < 20000){
return 50;
}else if(element["AvgWaitTime"] > 10000 && element["AvgWaitTime"] < 15000){
return 100;
}
});
}
isAllValuesSame = checkArrayValues(data);
Unfortunately, the code is not functioning correctly. Can you help identify the mistake I made?