Javascript 我想根据几个条件得到数组计数

Javascript 我想根据几个条件得到数组计数,javascript,Javascript,我从一个API得到以下结果 data: { "total_slots": int, "occupied_count": int, "occupied_slots" : [int] e.g.[452,453,459] (here each int in the array signfies an occupied slot), "slots_down" : [int] e.g.[460,462] (here each int in the array signfie

我从一个API得到以下结果

data: {
    "total_slots": int,
    "occupied_count": int,
    "occupied_slots" : [int] e.g.[452,453,459] (here each int in the array signfies an occupied slot),
    "slots_down" : [int] e.g.[460,462] (here each int in the array signfies a down slot)
}
我想要下列条件

VAR OCCUPIED, length of the list which are occupied minus length of common slots in occupied and slots_down
VAR TOTAL_SLOTS = total slots (which are 31 i think) - slots which are down
VAR AVAILABLE = (31 - length(slots_down)) - length( slots occupied AND not down)
插槽31是固定的

var ALL_SLOTS = [452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523];
如何满足OR/AND条件,如
VAR AVAILABLE=(31-长度(插槽向下))-长度(插槽已占用且未向下)

这是我的当前代码

s = JSON.parse(s);
console.log(s);
SLOTS_DOWN = s.slots_down;
var total_slots = s.total_slots;
SLOTS_DOWN = s.slots_down.length;
console.log('down slots are ' + SLOTS_DOWN);
total_slots = parseInt(total_slots) - parseInt(SLOTS_DOWN);
var occupied = s.occupied_count;
var available = parseInt(total_slots) - parseInt(occupied) - parseInt(SLOTS_DOWN);
这应该起作用:

数据={
“总槽数”:124,
“占用人数”:3,
“占用的_插槽”:[245326256],
“插槽向下”:[245136]
}
var下降但不下降occ=0;
数据槽向下映射(函数(v,i){
if(数据占用时隙索引(v)=-1){
向下但不向下;
};
})
var available\u slots=parseInt(data.total\u slots)-data.ock\u slots.length-down\u但\u not\u occ;
console.log(可用的\u插槽)这应该可以:

数据={
“总槽数”:124,
“占用人数”:3,
“占用的_插槽”:[245326256],
“插槽向下”:[245136]
}
var下降但不下降occ=0;
数据槽向下映射(函数(v,i){
if(数据占用时隙索引(v)=-1){
向下但不向下;
};
})
var available\u slots=parseInt(data.total\u slots)-data.ock\u slots.length-down\u但\u not\u occ;
console.log(可用的\u插槽)根据以下内容:

VAR占用,占用列表的长度减去公共值的长度 插槽已占用,插槽已关闭 VAR TOTAL_SLOTS=总插槽数(我想是31个)-停机的插槽数 可用变量=(31-长度(插槽向下))-长度(插槽已占用且未向下)

你可以试试这个:

var OCCUPIED = data.occupied_count -
          data.occupied_slots.filter(function(elem){
                                       return data.slots_down.indexOf(elem)>-1;
                 }).length;

var TOTAL_SLOTS = data.total_slots.length - data.slots_down.length;


var AVAILABLE = ((data.total_slots.length - data.slots_down.length)) - 
            data.occupied_slots.filter(function(elem){
            return data.slots_down.indexOf(elem)==-1;
       }).length
根据这些规定:

VAR占用,占用列表的长度减去公共值的长度 插槽已占用,插槽已关闭 VAR TOTAL_SLOTS=总插槽数(我想是31个)-停机的插槽数 可用变量=(31-长度(插槽向下))-长度(插槽已占用且未向下)

你可以试试这个:

var OCCUPIED = data.occupied_count -
          data.occupied_slots.filter(function(elem){
                                       return data.slots_down.indexOf(elem)>-1;
                 }).length;

var TOTAL_SLOTS = data.total_slots.length - data.slots_down.length;


var AVAILABLE = ((data.total_slots.length - data.slots_down.length)) - 
            data.occupied_slots.filter(function(elem){
            return data.slots_down.indexOf(elem)==-1;
       }).length

什么是
slots\u down
?还需要一系列slots\u down。您的销售代表的用户应该知道共享的重要性code@dev8080已经完成,但目前它没有处理插槽向下的内容什么是
插槽向下
?也需要一系列插槽向下。您代表的用户应该知道共享的重要性code@dev8080 已经完成,但目前它没有处理插槽。\u down thing占用的插槽和总插槽如何?占用的插槽和总插槽如何?