陣列指望我從一個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];
我如何能滿足或/與條件像VAR AVAILABLE = (31 - length(slots_down)) - length(slots occupied AND not down)
這是我當前的代碼
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);
是什麼'slots_down'? –
也需要一組slots_down。 – dev8080
與你的代表的用戶應該知道共享代碼 – Rajesh