Commit d9598d0eb73e9a34e87d4ed2755ab233e396bceb
1 parent
38912181eb
Exists in
master
and in
1 other branch
Salah pakai count, harusnya length
Showing 1 changed file with 10 additions and 1 deletions Inline Diff
lib/modems.js
1 | /* eslint-disable no-console */ | ||
2 | const DEBUG = !!process.env.DEBUG_KOMODO_CENTER_CP_EVO_MODEMS; | ||
3 | |||
1 | const config = require('komodo-sdk/config'); | 4 | const config = require('komodo-sdk/config'); |
2 | 5 | ||
3 | exports.modemsDictionary = (arrayOfModem) => { | 6 | exports.modemsDictionary = (arrayOfModem) => { |
4 | const modems = arrayOfModem || config.modems || []; | 7 | const modems = arrayOfModem || config.modems || []; |
5 | const retval = {}; | 8 | const retval = {}; |
6 | modems.forEach((modem) => { | 9 | modems.forEach((modem) => { |
7 | retval[modem.name] = modem; | 10 | retval[modem.name] = modem; |
8 | }); | 11 | }); |
9 | return retval; | 12 | return retval; |
10 | }; | 13 | }; |
11 | 14 | ||
12 | exports.enabledModems = (arrayOfModem) => { | 15 | exports.enabledModems = (arrayOfModem) => { |
13 | const modems = arrayOfModem || config.modems || []; | 16 | const modems = arrayOfModem || config.modems || []; |
14 | return modems.filter((modem) => !modem.disabled); | 17 | return modems.filter((modem) => !modem.disabled); |
15 | }; | 18 | }; |
16 | 19 | ||
17 | exports.outgoingModems = (arrayOfModem) => { | 20 | exports.outgoingModems = (arrayOfModem) => { |
18 | const modems = arrayOfModem || config.modems || []; | 21 | const modems = arrayOfModem || config.modems || []; |
19 | return modems.filter((modem) => !modem.disabled && modem.outgoing); | 22 | return modems.filter((modem) => !modem.disabled && modem.outgoing); |
20 | }; | 23 | }; |
21 | 24 | ||
22 | exports.randomModem = (arrayOfModem) => { | 25 | exports.randomModem = (arrayOfModem) => { |
23 | const modems = this.outgoingModems(arrayOfModem); | 26 | const modems = this.outgoingModems(arrayOfModem); |
24 | const modemCount = modems.count; | 27 | |
28 | if (DEBUG) { | ||
29 | console.log('DEBUG_MODEMS: Get random modems', { | ||
30 | haystack: modems, | ||
31 | }); | ||
32 | } | ||
33 | const modemCount = modems.length; | ||
25 | 34 | ||
26 | if (!modemCount) return null; | 35 | if (!modemCount) return null; |
27 | 36 | ||
28 | const idx = Math.floor(Math.random() * modemCount); | 37 | const idx = Math.floor(Math.random() * modemCount); |
29 | return modems[idx]; | 38 | return modems[idx]; |
30 | }; | 39 | }; |
31 | 40 |