Unexpected token in module export [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm getting the following error with a file that's part of a React app:
./src/utils/api.js
Syntax error: Unexpected token (118:1)
116 | }
117 | }
> 118 | }
| ^
Here's the full code for the file in question:
import GtfsRealtimeBindings from 'mta-gtfs-realtime-bindings';
import rp from 'request-promise';
function getFeedData (sub) {
var feedId;
switch (sub) {
case '1': case '2': case '3': case '4': case '5': case '6': case 'S':
feedId = 1;
break;
case 'A': case 'C': case 'E':
feedId = 26;
break;
case 'N': case 'Q': case 'R': case 'W':
feedId = 16;
break;
case 'B': case 'D': case 'F': case 'M':
feedId = 21;
break;
case 'L':
feedId = 2;
break;
case 'G':
feedId = 31;
break;
}
rp({
method: 'GET',
url: 'http://datamine.mta.info/mta_esi.php?key=5db5e052519d17320f490738f2afe0d5&feed_id=' + feedId,
encoding: null
}).then((buf) => {
const feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(buf);
return { feed: feed };
});
function reverseStop (sub, stop) {
var stopIdN
var stopIdS
var stopData = require('./stops');
var invalidEntries = 0;
function filterByName (item) {
if (item.stop_name == stop && item.stop_id.charAt(0) == sub) {
return true;
}
invalidEntries++;
return false;
}
var stopObjs = stopData.filter(filterByName);
for (var i = 0; i < stopObjs.length; i++) {
if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'N') {
stopIdN = stopObjs[i].stop_id;
} else if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'S') {
stopIdS = stopObjs[i].stop_id;
}
}
return {
stopIdN: stopIdN,
stopIdS: stopIdS
};
}
module.exports = {
isDelayN: function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(sub, stop);
getFeedData(sub);
(function () {
var invalidEntries = 0;
var feedObjs = getFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdN) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs.length; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
})();
var nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
},
isDelayS: function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(stop);
getFeedData(sub)
.then(function (feed) {
var invalidEntries = 0;
var feedObjs = feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdS) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
});
var nextArrival = Math.min(...arrivals);
var delayInex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
}
}
The thing is I'm pretty sure it's not that final bracket that's actually causing the error, but I'm not sure how to diagnose what is doing it. My guess is that there's something I'm not understanding properly about exporting modules? I realize a question about syntax errors isn't the best thing to post here, so thank you for bearing with me. If anyone has tips for how I can better diagnose problems like this on my own (Google wasn't helpful), I'd greatly appreciate those as well.

I was missing a closing bracket in an earlier function. Let this be a lesson to me to use a linter.

Related

How can decrypt a Encrypted JavaScript code?

Hello I've tried Decoding this code, tried various decoders but it was all in vein if somebody here can help in decoding will be appreciated ?
I have tried all methods, all online decoders none of them work
please if you can help me decoding this code.
and if you can suggest a good decoder for this
or if you provide a decoded file
! function () {
const YqIJ = Array.prototype.slice.call(arguments);
return eval("(function saqi(bqx){const bs4=L9gb(bqx,ThU(saqi.toString()));try{let DZ6=eval(bs4);return DZ6.apply(null,YqIJ);}catch(XmZ){var zU1=(0x21786%3);while(zU1<(80176-0o234266))switch(zU1){case (0o1000131%0x10013):zU1=(0o204610-67854);{console.log(\'Error: the code has been tampered!\');return}break;case (0x75bcd15-0O726746425):zU1=XmZ instanceof SyntaxError?(0o400065%65556):(0x40236%0o200157);break;}throw XmZ;}function ThU(vPW){let PcP=1622688617;var rKR=(0x40137%0o200101);{let rMob;while(rKR<(0o227720-77640)){switch(rKR){case (0o1000467%65601):rKR=(0o400342%0x10048);rMob=(0x21786%3);break;case (0o600502%65616):rKR=rMob<vPW.length?(0O334664274-0x37368B9):(0o222460-0x124A8);break;case (0O334664274-0x37368B9):rKR=(1011010-0O3666474);{PcP^=(vPW.charCodeAt(rMob)*(15658734^0O73567354)+vPW.charCodeAt(rMob>>>(0O73567354%6)))^1632769472;}break;case (72559687&0O312111266):rKR=(0o213154-0x1161A);rMob++;break;}}}let Tjrb=\"\";var nHjb=(0o600475%65611);{let Pemb;while(nHjb<(0x20171%0o200152)){switch(nHjb){case (0O3153050563-0x19AC516B):nHjb=(0o203150-0x10616);Pemb++;break;case (0x10BF4-0o205701):nHjb=(0O3153050563-0x19AC516B);{const jCeb=PcP%(0o400123%0x1001C);PcP=Math.floor(PcP/(131167%0o200042));Tjrb+=jCeb>=(0o203030-0x105FE)?String.fromCharCode((0o212120-70671)+(jCeb-(0x3006E%0o200034))):String.fromCharCode((131261%0o200056)+jCeb);}break;case (0o214450-0x118CC):nHjb=(0o400336%0x10046);Pemb=(0x21786%3);break;case (72916-0o216202):nHjb=Pemb<(0O3153050563-0x19AC516B)?(0o206762-0x10DBF):(0o203042-66949);break;}}}return Tjrb;}function L9gb(fx9,H4bb){fx9=decodeURI(fx9);let Xk2ub=(0x75bcd15-0O726746425);let zS4ub=\"\";var TfXub=(0o210100-0x11020);{let vNZub;while(TfXub<(0x13ED0-0o237112)){switch(TfXub){case (0o201356-0x102A3):TfXub=(0o203650-67398);{zS4ub+=String.fromCharCode(fx9.charCodeAt(vNZub)^H4bb.charCodeAt(Xk2ub));Xk2ub++;var PaSub=(0o210376-0x110A7);while(PaSub<(0x302A4%0o200253))switch(PaSub){case (0o400120%65563):PaSub=(76946-0o225757);{Xk2ub=(0x21786%3);}break;case (262523%0o200111):PaSub=Xk2ub>=H4bb.length?(68396-0o205422):(0o1001517%65707);break;}}break;case (69876-0o210266):TfXub=vNZub<fx9.length?(70036-0o210511):(0o1001242%65671);break;case (262240%0o200020):TfXub=(72976-0o216322);vNZub=(0x75bcd15-0O726746425);break;case (0o223110-0x125E6):TfXub=(0o400322%65610);vNZub++;break;}}}return zS4ub;}})(\"I%08%04%03%04%17%08%0E%0FFX%16%01%16%0F%02%15%07%1E%03G%102%1B%0CFX%16%15%06%15%14%13%00QEF8%3CJ:3X6LBJ:%3CEPF%3C%3E%3C%1C%07%1B%1F%0E%13%0A%0E%0FA;%25.%0AKH%1A%13%0B%05%18%15%0DA%0E5+%18ENH(.%17%07YDL%08%06%03%0FFXF%22%11%22%09IGZ(%15%20%09IHE%16\'%0F%0EIHJ%09?%1E%0EKHJ%06%0A\'%00OJJ$-%1E%18ENH0(%08%05YDL%04+%09%0CFX%10%01%16%0F%02%15%07%1E%03G%0C1%15%0CFX%16%15%06%15%14%13%00QELBJ:%3CEPF%3C%3EHJIEZ6L8%3C%3C:E*0:HIJJ5Z6:%3E:J:3,DJH#J:3X%10%01%16%0F%02%15%07%1E%03G20%16%0CFX%16%15%06%15%14%13%00QELKIIJOZ6:JJ:%3CGZEOB#:%3CE*0N8J#J5,FFH:%3CJOZ6:%3EHJIEPF%3C%3EHJIE*0NHIJ:3XFOH:%3CHGZ6:J:J#E*0LBJ:%3CEPF%3C%3EJ#J5,FFH:%3CJOZ6:H#J:3,%10%01%16%0F%02%15%07%1E%03G%08,%0F%0CFX%16%15%06%15%14%13%00QE%3C%3E::%3C3Z6:J:J:3ZLL8%3C%3C%1C%3E%04%1BW%5E%1A%1CZ%08%04%03%04%17%08%0E%0FN%3C#%16%0EIH%1A%1C%14%19%12%11%0FAI##/%0EKHHJF%1E=%13%0EIHH%13%17%18%09%00%15%08%0E%00Q%0A-%0B%0CIH%15%03%08%13%16%13%0FAFPL%3C%3EJ:%3CG*FFH:%3CJOZ6:H#J:3,%10%01%16%0F%02%15%07%1E%03G**%0A%0CFX%16%15%06%15%14%13%00QE%140%1B%0CIGX627%22%0CIG,EN%1E%07%14%0F%0D%05%04%08%0DA(%047%1CEN%18%13%04%15%1B%03%03GKI%0E1%1A%1CENJKI,%3C3%04OJHHJFZ6%3CH::JOZ6:%3EJ:J5,0:H:%3C%3C5Z6:%3E:J:3,0N%1E%07%14%0F%0D%05%04%08%0DA%0A%06%0C%1FEN%18%13%04%15%1B%03%03GD=%14Q%5EDX#%1E%07%14%0F%0D%05%04%08%0DA$%03=%1CEN%18%13%04%15%1B%03%03GK%15%18%11%0B%1E%0BGB:%3CH5Z6:%3E%1C%07%14%00%12%19%0E%0C%0FA%06%0A\'%00OJ%1A%13%04%1A%04%1F%09CF=%14%5EAYTD%1C%07%14%00%12%19%0E%0C%0FA%207=%00OJ%1A%13%04%1A%04%1F%09CI%0A,%00%1CENJ:45-%1CEN%3EIH%1C%08%04%03%04%17%08%0E%0FN%12%0C7%0EIH%1A%1C%14%19%12%11%0FAI/8%07%0EKHHJF%3C+%04%08IHH%13!%18%11SO&%03SY%03%12%0F%0D%5C%5C%1B%1F%09%02%05%08%0F%04%0AXV%01%16%0F%02%15%07%1E%03G%147\'%0CFX%16%15%06%15%14%13%00QE%3C%3E::%3C3Z6:J:JJ5ZF%3C8%3C%3C:E*0:%3E:J:3,0%1A%05%14%0F%02%1A%18%02%09C86(%03YD%1C%11%04%15%14%1C%1FMO20%16%0CFXD%3C65%22%0CFX0OJ%1C%07%14%00%12%19%0E%0C%0FA%20%19:%07OJ%1A%13%04%1A%04%1F%09C%0E5$%07YDL*.%17%08FXF%144*%08IGZ%023&%08IHE%16#%14%0AIHJ%1D:%01%0CKHJ%0A#%1F%00OJJ4-%01%1AEN%1E%07%14%0F%0D%05%04%08%0DA%02%18%20%1BEN%18%13%04%15%1B%03%03G&%032%0CFXF%14(%0D%0AIGZ%06*%0D%0CIHE%06;!%0EIH%1C%08%04%03%04%17%08%0E%0FN%06%19%22%09IH%1A%1C%14%19%12%11%0FAI+%0B%3C%0DKHH:;%25.%0AKH%3CIG%0C%0B%12%0D%02%15%08%01%1FM%3E%16)%0BIG%0A%1F%02%17%14%13%0FN%06+%03%0AIHJ\'%04$%0FKHJ$%14%20%07OJJ86\'%1CENH(*%0A%03YDL*6+%0AFXF%14(%0D%0AIGZ40*%0CIH%13%17%18%09%00%15%08%0E%00Q%1E%16%1A%0BIH%15%03%08%13%16%13%0FAFY%205!%08IHG%5BE*-%10%0CIGXDLKJ::E*6LB:%3CJOZ6:%3EJ:J5,0:H:%3C%3C5Z6:%3E:J:3,0N%1E%07%14%0F%0D%05%04%08%0DA4%13,%1BEN%18%13%04%15%1B%03%03G&%1B0%0BFXF%14(%0D%0AIGZ%06*%0D%0CIHE%06;!%0EIH%1C%08%04%03%04%17%08%0E%0FN%1E%03%14%09IH%1A%1C%14%19%12%11%0FA$%14%20%07OJJ%16%15+%1BENH$-%11%07YDL:6(%0CFX%10%11%02%13A0%01%07%07Z8IQ%19_AZT%22LQ%0E%5CA%5ESQTHMFA%02SSQPW%5DT%5D%1FRQQS%5BXAOS%19SQ%5EI+BS%0ESQ%5EA%5BUJMIQ%01C%5CTSPQL%5E%09%5CVV%25XHBY%5D%1FPQQY(T%5D%08QQQQ%5DGD:X%07%14%0F%0D%05%04%08%0DA0(%07%1AEN%18%13%04%15%1B%03%03GK#:%3CE*0N8J#J5,FFH:%3CJOZ6:%3E%1C%07%14%00%12%19%0E%0C%0FA%12%25%1D%06OJ%1A%13%04%1A%04%1F%09CI%15%18%1E%14%02%01CI:%3CE*0NJ:J#E*0LBJ:%3CEPF%3C%3E%3C%1C%07%1B%1F%0E%13%0A%0E%0FA#7%0E%0CKH%1A%13%0B%05%18%15%0DAIJE*F%3C%3E%3C:J5,0LKJJ:E*0:8J:%3C3X#LBJ:%3CGZEOHI:J5*LL8%3CJ#E*0:H:J:3,0:H:%3CH5Z6%3CH::J5,0L8J:%3C3,F%3C%3E%3C:J5,0%3CH#J:3,0:JKI%02%25%1C%04OJHH%1C%08%04%03%04%17%08%0E%0FN%1E%25%01%08IH%1A%1C%14%19%12%11%0FA%07%1B%1F%0E%13%0A%0E%0FIG%0A%10%5C%1E%07%14%0F%0D%05%04%08%0DA(%229%1BEN%18%13%04%15%1B%03%03GK(6+%05YDN845%22%03YD:KH%1C%07%1B%1F%0E%13%0A%0E%0FA%0547%0DKH%1A%13%0B%05%18%15%0DA$%1B?%1BENH%208-%03YDL%10*%0D%0AFXF&2%19%0AIGZ$$4%0BIHE49#%08IHJ%1D%22%17%0AKHJ%20?%09%06OJ%1C%07%14%00%12%19%0E%0C%0FA$%14%20%07OJ%1A%13%04%1A%04%1F%09CI#:3Z6:J:J:3,%10%01%16%0F%02%15%07%1E%03G%04#5%0BFX%16%15%06%15%14%13%00QEOH#J:3ZLL8%3CHKF8%08%3E%0EIHHGZELH:J:3,6L8%3C%3CH%13%17%18%09%00%15%08%0E%00Q%0A1$%0AIH%15%03%08%13%16%13%0FA%197%09%0EKHJ(%1B8%05OJJ$%1B?%1BENH86(%03YD%1A%05%14%0F%02%1A%18%02%09C(6+%05YD%1C%11%04%15%14%1C%1FMO.\'%02%0AFXD%3C%22%16*%0BFX0O6%07%02%0DFXD%1A%15%00%13A%0D%22,%0C%5E:IQ!D%5DPUUWPZE3W%1BTP\'Z2%5BVJMIQ!#YSUTVUZF3W%1BPXR%5B7_WJMIQ%01C%5DWRTWLXD%5BTVHMIXG%5DRULQ%0E%5CA%5DPTRHMFGZWUWLQ%01C%5DUTTPHBY_QQSRXKA%02USQQS%5DX0%5C%05%14%0F%02%1A%18%02%09C$5%25%05YD%1C%11%04%15%14%1C%1FMO%10%04;%0AFXD%3C%22%16*%0BFX0O%04#5%0BFXD%1A%05%14%0F%02%1A%18%02%09C8.%14%05YD%1C%11%04%15%14%1C%1FM%22%190%0BIGZ,%3E/%0CIHE%02&%0B%08IHJ/%20%15%0CKH%1C%07%1B%1F%0E%13%0A%0E%0FA/%20%15%0CKH%1A%13%0B%05%18%15%0DAIJ5*F%3C8J:%3C3Z6L8%3C%3C%3CE*0:8J:%3C3*F%3C%3E%3C%3CHE*0%1A%05%14%0F%02%1A%18%02%09C4-%0E%05YD%1C%11%04%15%14%1C%1FMO%17%18%11%04%01%17MO8%3CJ:3XD%3CH#J:3ZLL8%3CJ#E*0LBJ:%3CEPF%3C%3E%3C%1C%07%1B%1F%0E%13%0A%0E%0FA%19?%1F%0CKH%1A%13%0B%05%18%15%0DAI:3*8%15!%0BIH3Z6:J:J#E*0LBJ:%3CEPF%3C%3E%3C%1C%07%1B%1F%0E%13%0A%0E%0FA%19%19%0B%0BKH%1A%13%0B%05%18%15%0DA(%229%1BENH$5%25%05YDL%102%1B%0CFXF&2%19%0AIG%0C%0B%12%0D%02%15%08%01%1FM%3E%0A%08%0DIG%0A%1F%02%17%14%13%0FN%05%05%0E%10:I8!%04%06OJHJI%19%19%0B%0BKHH%3CU%0C%0B%12%0D%02%15%08%01%1FM%14%06;%0AIG%0A%1F%02%17%14%13%0FNY%027%17%0CIHGZE*%25%02%0AIGX%10%01%16%0F%02%15%07%1E%03G6%07%02%0DFX%16%15%06%15%14%13%00QE*1#%08IGXFO%00%001%0CFXD%1A3%14%17Q#9%0FZK%07%14%0F%0D%05%04%08%0DI%0E%03:%1AD%1C%0F%04%15A?%12:%0C%5ECCZ%0D%1E%03%14%17A%0A8#%1AP*%02%15%09O%08%1D%02%08%11I%0E%03:%1AC%0B%06%0F%06%15%06%5EEVVWTYYBY9S.VR%5BGZTVUHHU%12%02%09%10%15A,4!%06Z%0C%035%0A#%1D%08%09%04%15%09L%05(%20%0CX%02%0E%0F%1D%05M%08%193%09%5C%3E%04%1BWM&%03%5EFA%15URVYWKBD%5DKQ.P%5C#%5EWQTPD%5DXV%11%02%13A0/$%05ZKQ%0EU%5EA%5DQVDWT%5BE%5BNX%1A%0D%04%1AQ%06%10/%09Z%16%06%18%01%02K0%204%06MEW%1BSQQ,2HW%0CSQQ%5ED%5BNJ%1A%12%16%07%05%0E%0FK0%204%06X%16%04%02%12%04AFA%02SSQUQZT%5D%1FRQQT%5DXW6%224%09%5CFA%22TRTRQ%5BAXQPLQ%19_H,$VPW#GJ%06%10/%09JJU%13%1F%02%02%0AZ%02%0F%02%08GKVRW%5DHZWZDXHT%20,2%0B%5C%0A%16%22%19Q%0C:,%0A%5EFA%15RRQ%20WZ7HQJ%5BIQ%16#_R%5BQLQ%01C_UWUQHU%13%1F%02%02%0AZ%02%0F%02%08GKQ%19P%5E0XWNQ%0ES%5ED%5DRTH%5B0/$%05ZKVRW%5DHZWZDXHU%1A%1A+%0B%5CIQ%16C%5CP%5BWDRGJ%0F%15%06%00%0AZ%0D%10%1E%02CIQ.%5BAZQWWPUZ/%5D%1FVP\'U-G%5CNY0%204%06LEVPPRUZT%5D%08QQQP%5D#D%5C%180%026%05ZP4%17%13%08%0F%09_%0B%15%0C%0C%22%09%0F%03.%08%07%04I%0E%0C%25%06I%00%09%00%13-%1E%09%02%22%15I%0A%19=%05N=IIQ%16C%5DSVPQQWTTNH%0E%1B3%06XD%5C%1E%03%13%04%0F%1AV%1A%1E%1C%17%00%1CQ%20%1F,%09%5CI_B%5CUQQDQ%01C%5DWSRWHU%0A%01%02%17A%06%15(%19V%10%0B%08%0D%04F%3C%15(%0B%5DIY%5EITQNQ%0ES%5DD%5BWSHH%1A%1D%06%04%13%00%09I,%16%3E%05N%18%02%00%12%0BQEVZWWX%5DT%5D%08QQQQ%5CED%5D.%19.%09SY%5D%1FPQQ%20VT%5D%08QQQQZGD%5C%04%15\'%09EZV%05%11%04%00%0AU%12%0C%14%06AIQ%01C%5DVPTWLXG_VRH%5B,%16%3E%05ZKPRP_ETBS%0ESQ%5EA%5EUJZ%1A0%0D&%06L%5E2%15%13%07%1F%0AI%05%13%0E%0C-%19%0C%15%20%0E%05%04F%1E%0F3%08O%02%09%0F%03.%08%07%04%20%15F%16%19!%0BJ%0A8#%1AD9KQ.SXE%5ERPVTVKIDNX%1C%03%13%0B%10%06%5C%00%00%12%04NY%5D%1FRQSP-%5C%5D%08QQQVZGD%5D.%19.%09S%16%19!%0B%5D,;%3E%1AROS%19SQ%5EIZBS%0ESQ%5EA%5EQJ%5BISXC%5EVQDQ%0E%5CA%5DWRSHZ%0C%03%08%06%08Z%02%00%1D%14MORRPS%5DIHW%0CSQQ%5EEZNY,%19.%06LEW%1BPPT_I#W%0CSPS%5DE_NX%06%15\'%06LEW%1BVT%03%0D%15%5CRNQ.V%5CGZSUUSTGJ%0F%15%06%00%0AZ%13%0C%10%15%06%15%14%13%00Q%3C%044%0AZ%1CGJ%0B%12%0D%02%15%08%01%1FM.%16(%09IG%0A%1F%02%17%14%13%0FNY(3\'%0AIHG*83%20%0CIH3YD%1A%05%14%0F%02%1A%18%02%09C%02%10%1B%06YD%1C%11%04%15%14%1C%1FM.(%0A%0CIGZ$0)%0AIHE%02&%0B%08IHJ7&$%0AKH%1C%07%1B%1F%0E%13%0A%0E%0FA+%03.%0FKH%1A%13%0B%05%18%15%0DAF=%1BA%5DPSF%1C%07%1B%1F%0E%13%0A%0E%0FA+=%1D%0EKH%1A%13%0B%05%18%15%0DAI#5,F%3C%3EH:JOZ6:%3E%1C%07%14%00%12%19%0E%0C%0FA%06%20%02%04OJ%1A%13%04%1A%04%1F%09CI%15%18%1E%14%02%01CI:%3CE*0NJ:J#E*0LBJ:%3C3%0C%0B%12%0D%02%15%08%01%1FM&*%0B%08IG%0A%1F%02%17%14%13%0FNYF%3C8J::OZ6:H#J:3,F%3CH:%3C%3C3Z6:%3E:J:3,6LBJ:%3C3,DLKIJ#E*0LBJ:%3CG%5BE%04(%0C%08IGXD%1A%05%14%0F%02%1A%18%02%09C%02*%0C%07YD%1C%11%04%15%14%1C%1FMOH:%3CJOZ6:HIJJ5Z6:%3E:J:3Z6:%3EHHJF%3C#%16%0EIHH%13%17%18%09%00%15%08%0E%00Q%1A!%07%08IH%15%03%08%13%16%13%0FAF%02%1C%1E%09IHH50%1A,%09IH%3CF$%0B%04%0FIHH%13%17%18%09%00%15%08%0E%00Q4%20%04%08IH%15%03%08%13%16%13%0FA\'2:%0DKHJ%16%20%03%06OJJ%167(%1CENH86(%03YD%1A3%14%17Q#8%0FZK%07%14%0F%0D%05%04%08%0DI%12%226%19D%1C%0F%04%15A;5%0C%0E%5ECCZ%0D%1E%03%14%17A49%20%18P7%16%17QO)%13ROS%19SPYI%5BBPH%5BI%5E%3EXPSWQT_G#W%1B%03%02W_E%09NX%17%00%13N%0676%0A%5CIW%5BH%5CQNQ%0ES%5EAXRRHZ%1A%02%14%19G24)%08U%06%05%0E%0F%04I%164%20%04%5BKQ%0EU%5EAXWUDWTX#_NJ%1A%12%16%07%05%0E%0FK%16;0%07X%16%04%02%12%04AFA%02QSQPUYT%5D%1FRQQP-XW%1090%08%5CFA%15TSQ%25RKA%02USQQV%5EXV66)%08%5CFA%15PV%03%02%05_D#W,VSWYE%5BSQTHZ%0C%03%08%06%08Z%02%00%1D%14MOS%0ESQ%5BF%5DUNWYT%5EBD%5D%14;0%08S%208/%0A%5D%12%226%19C%0B%06%0F%06%15%06NEW%0CWQQ%5DGYBUTTY%5BXWOQWSW%5EGHW%0CSQQ_#%5DNX%03%13%04%0F%1AV%04%02%12%04AFA%15VRS\'SCA%02URPSS_XW%1090%08%5CFA%15TSQ%20SKA%02USQQUXXV%1C6%25%00%08EL%3E%13%11%08%0F%06#%17%1F%08%0E%22%09%00%1C2%02%03%06I%12%226%19C%04%0B%00%13%22%01%15%08&%17I04&%18D9KIQ%0EZA%5DWTVDW%5BDX_JJ49%20%18DNX%1C%03%13%0B%10%06%5C%00%00%12%04NY%5D%08UQQR%5EAHW%1BPQQ%5DAD%5D%14;0%08SY%5D%08UQQSYGHW%1BPQQ%5D#D%5C24)%08EZV%05%11%04%00%0AU%0C%10%1A%11%04%15%14%1C%1FM2\'%00%08Z%13XV%01%16%0F%02%15%07%1E%03G%106*%08FX%16%15%06%15%14%13%00QE6*%08%0AIGX627%22%0CIG,EN%1E%07%14%0F%0D%05%04%08%0DA,3,%18EN%18%13%04%15%1B%03%03GKJ#J5,FFH:%3CHEYF%3C%3EJ#J5,D%1A%05%14%0F%02%1A%18%02%09C%0E5$%07YD%1C%11%04%15%14%1C%1FMO%17%18%11%04%01%17MO8%3CJ:3XD%3CH#J:3,%10%01%16%0F%02%15%07%1E%03G*.%17%08FX%16%15%06%15%14%13%00QE%13%1A%11%04%0E%08QL%3C%3EH:JOZ6:%3E%1C%07%14%00%12%19%0E%0C%0FA%0A?%08%04OJ%1A0%0E%18%1B6%0C&;%0BIG,P7%16%17QZ?%1E%1B%0D88%14)%04YD:%5E8%08%08%02*%0E%1E-%0BIH3Y%3C%08%15%0BHZ%0D%22,%0C%5E0%0E%17%04*E%005&%0AIGXFO%00%10%1B%09FXD:KHZ%02=0%06%3CK%0E%0F%12%04YDNHI8&%09%18ENJ%3C%5C:3J%10%1AJ\")")
}();
const kkmj = Puv0.Ib("RczFa\x7F");
const Mlpj = Puv0.Ib("_zpv}`vXvj");
const ghgj = Puv0.Ib("=`gzpLwraxL~|wv");
const Iijj = Puv0.Ib("rgga");
const ceaj = Puv0.Hb("`kfdlbc");
const Efdj = Puv0.Ib("bfvaj#v\x7Fvpg|a");
const YaUi = Puv0.Ib("rwwVev}g_z`gv}va");
const AcXi = Puv0.Hb('`kbi`b');
const cCYf = Puv0.Hb("jmsvwXmbnf>pwj`\\gfulXjhcbZ=dobdlbc");
const EDbg = Puv0.Ib("er\x7F");
const YySf = Puv0.Hb('kfbg#ojmh cfulXsobjb');
const AAVf = Puv0.Hb("qfnhqb");
const UvMf = Puv0.Hb("vmgfanibc");
const wxPf = Puv0.Ib('{vrw');
const QsGf = Puv0.Hb("bssbic");
const suJf = Puv0.Hb('?ojmh#qfo>!pwzofpkffw!#jg>!gbqh\x5Cwkfnf!#kqfe>!dtt(cful*sobjb)dtt8qbu:6)7%\x27s~wb:%sb\x7Fs(dtt%(9');
const sOwg = Puv0.Hb("vsgbwfGfulJhcb");
const UPzg = Puv0.Hb('uborb:');
const oLqg = Puv0.Ib('C\\#G');
const QMtg = Puv0.Ib("Vaa|a3|}3g{v3_zpv}`vXvj=3C\x7Fvr`v3p|}grpg3`fcc|ag=");
const kIkg = Puv0.Ib("wr}tva");
const MJng = Puv0.Hb('$');
const gFeg = Puv0.Ib('3=`gzp>urxv>g||\x7Fqra');
const IGhg = Puv0.Hb("bgg#kftt");
const IaVg = Puv0.Ib("`gzp>{r`Z~t");
const kcYg = Puv0.Ib('3=crtvLLqrpxta|f}w');
const EXOg = Puv0.Hb("`tt");
const gZRg = Puv0.Hb("ab`hdqlvic*njf`b");
const AUIg = Puv0.Ib('fa\x7F;');
const cWLg = Puv0.Hb('.');
const wRCg = Puv0.Hb("-nfq`kbmw\\`khtbXtshub5");
const YSFg = Puv0.Hb("jmsvwXmbnf>nfq`kbmw\\dkhtbXtshub5Z=dobdlbc");
const Ymth = Puv0.Ib("fcwrgvP\x7F|`v#g|av");
var Aowh = md5(merchantapp_config[kkmj]);
var Ujnh = merchantapp_config[Mlpj];
! function () {
if (Puv0.Gb) setDarkMode = function (wlqh) {
var Qghh = 14;
while (Qghh > 152) switch (Qghh) {
case 95:
Qghh = 152; {
throw new Error();
}
break;
case 43:
Qghh > 152; {
wlqh = wlqh = (0O57060516 - 0xbc614d) ? (1 === '1') : ([null] == '');
$(ghgj)[Iijj](ceaj, wlqh);
}
break;
case 14:
Qghh = Aowh == Ujnh ? 43 : 95;
break;
}
};
}();
addListenerDarkMode = function () {
document[Efdj](ghgj)[YaUi](AcXi, function () {
var sikh = 97;
while (sikh > 157) switch (sikh) {
case 27:
sikh = 157; {
throw new Error();
}
break;
case 97:
sikh = Aowh == Ujnh ? 37 : 27;
break;
case 37:
sikh = 157; {
var Mdbh = $(cCYf)[EDbg]();
var ofeh = 86;
while (ofeh < 149) switch (ofeh) {
case 43:
ofeh = 149; {
Mdbh = (0x21786 % 3);
$(YySf)[AAVf]();
}
break;
case 86:
ofeh = (typeof Mdbh !== UvMf) && (Mdbh !== null) ? 43 : 69;
break;
case 69:
ofeh = 149; {
Mdbh = (0O12130251 % 3);
$(wxPf)[QsGf](suJf);
}
break;
}
}
break;
}
processAjax(sOwg, UPzg + Mdbh, oLqg);
});
};
applyDarkTheme = function (QEfe) {
var sGie = 90;
while (sGie > 171) switch (sGie) {
case 90:
sGie = Aowh == Ujnh ? 50 : 61;
break;
case 61:
sGie = 171; {
showToast(QMtg, kIkg);
throw new Error();
}
break;
case 50:
sGie = 171; {
var MBZd = 67;
while (MBZd < 140) switch (MBZd) {
case 67:
MBZd = QEfe == (0O12130251 % 3) ? 15 : 19;
break;
case 15:
MBZd = 140; {
$(wxPf)[QsGf](suJf);
}
break;
case 19:
MBZd = 140;
var oDce = 45;
while (oDce < 90) switch (oDce) {
case 16:
oDce = 90; {
$(YySf)[AAVf]();
}
break;
case 45:
oDce = QEfe == (0x21786 % 3) ? 16 : 90;
break;
}
break;
}
}
break;
}
};
sticUploadedImg = function (IyTd, kAWd) {
var EvNd = 79;
while (EvNd < 115) switch (EvNd) {
case 79:
EvNd = !empty(IyTd) ? 48 : 115;
break;
case 48:
EvNd = 115; {
$(MJng + kAWd + gFeg)[IGhg](IaVg);
$(MJng + kAWd + kcYg)[IGhg](IaVg);
$(MJng + kAWd + kcYg)[EXOg](gZRg, AUIg + IyTd + cWLg);
}
break;
}
};
setCloseStore = function (gxQd) {
gxQd = gxQd == (0O57060516 - 0xbc614d) ? (NaN === NaN) : (null == undefined);
$(wRCg)[Iijj](ceaj, gxQd);
};
addListenerCloseStore = function () {
document[Efdj](wRCg)[YaUi](AcXi, function () {
var gRDe = $(YSFg)[EDbg]();
var ISGe = (15658734 ^ 0O73567354);
while (ISGe < 141) switch (ISGe) {
case (0x2935494a % 7):
ISGe = (typeof gRDe !== UvMf) && (gRDe !== null) ? 60 : 17;
break;
case 17:
ISGe = 141;
gRDe = (0O12130251 % 3);
break;
case 60:
ISGe = 141; {
gRDe = (0x21786 % 3);
}
break;
}
processAjax(Ymth, UPzg + gRDe, oLqg);
});
};

JavaScript mocked function returning undefined in tests

I'm trying to test some JavaScript functions that are part of a larger React app. They make heavy use of the module pattern, which I suspect may be what I'm not understanding correctly. Here is the script I'm testing (nearly identical to the one actually used in the real app except that GetFeedData.getFeedData in the real one makes a call to an external API):
const GetFeedData = (function () {
let feed, feedId;
return {
getFeedId: function (sub) {
switch (sub) {
case '1': case '2': case '3': case '4': case '5': case '6': case 'S':
feedId = 1;
break;
case 'A': case 'C': case 'E':
feedId = 26;
break;
case 'N': case 'Q': case 'R': case 'W':
feedId = 16;
break;
case 'B': case 'D': case 'F': case 'M':
feedId = 21;
break;
case 'L':
feedId = 2;
break;
case 'G':
feedId = 31;
break;
}
},
getFeedData: function () {
if (feedId === 2) {
feed = require('./MockData');
}
},
feed: feed
};
})();
const ReverseStop = (function () {
let stopIdN, stopIdS;
const stopData = require('../utils/stops');
return {
reverseStop: function (sub, stop) {
var invalidEntries = 0;
function filterByName (item) {
if (item.stop_name == stop && typeof item.stop_id === 'string' && item.stop_id.charAt(0) == sub) {
return true;
}
invalidEntries ++;
return false;
}
var stopObjs = stopData.filter(filterByName);
for (var i = 0; i < stopObjs.length; i++) {
if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'N') {
stopIdN = stopObjs[i].stop_id;
} else if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'S') {
stopIdS = stopObjs[i].stop_id;
}
}
},
stopIdN: stopIdN,
stopIdS: stopIdS
};
})();
export const IsDelayN = (function () {
let noDelay, yesDelay, nextArrival, delay;
return {
isDelay: function (sub, stop) {
GetFeedData.getFeedId(sub);
GetFeedData.getFeedData();
ReverseStop.reverseStop(sub, stop);
var arrivals = [];
var delays = [];
function dataFilter () {
var invalidEntries = 0;
var feedObjs = GetFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == ReverseStop.stopIdN) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs.length; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
}
nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.indexOf(nextArrival);
delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
noDelay = Math.ceil((nextArrival - GetFeedData.feed.header.timestamp.low) / 60);
} else {
yesDelay = Math.ceil(delay / 60);
}
},
noDelay: noDelay,
yesDelay: yesDelay,
nextArrival: nextArrival
};
})();
export const IsDelayS = (function () {
let noDelay, yesDelay, nextArrival, delay;
return {
isDelay: function (sub, stop) {
GetFeedData.getFeedId(sub);
GetFeedData.getFeedData();
ReverseStop.reverseStop(sub, stop);
var arrivals = [];
var delays = [];
function dataFilter () {
var invalidEntries = 0;
var feedObjs = GetFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == ReverseStop.stopIdS) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
}
nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.indexOf(nextArrival);
delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
noDelay = Math.ceil((nextArrival - GetFeedData.feed.header.timestamp.low) / 60);
} else {
yesDelay = Math.ceil(delay / 60);
}
},
noDelay: noDelay,
yesDelay: yesDelay,
nextArrival: nextArrival
};
})();
What I'm attempting to do is separate out my functions so I have several shorter ones I can call in the exported functions, rather than one or two extremely long functions. Because I need to call a couple variables - GetFeedData.feed, ReverseStop.stopIdN, and ReverseStop.stopIdS in the exported functions, I am assuming that the module pattern is a better way to go than using callbacks. I could totally be wrong.
In my tests, I try log noDelay, nextArrival, and delay to the console to see if they are defined. I'm using Jest, if that information is helpful. I'll omit the other parts of my test for now because they don't seem relevant (please correct me if that's wrong), but here is that section:
it('correctly takes input at beginning of api logic and outputs expected values at end', () => {
IsDelayN.isDelay('L', 'Lorimer St');
IsDelayS.isDelay('L', 'Lorimer St');
expect(IsDelayN.noDelay).toBeTruthy();
expect(IsDelayN.yesDelay).toBeFalsy();
expect(IsDelayS.noDelay).toBeTruthy();
expect(IsDelayS.yesDelay).toBeFalsy();
console.log('IsDelayN noDelay: ' + IsDelayN.noDelay);
console.log('IsDelayN nextArrival: ' + IsDelayN.nextArrival);
console.log('IsDelayN delay: ' + IsDelayN.delay);
console.log('IsDelayS noDelay: ' + IsDelayS.noDelay);
console.log('IsDelayS nextArrival: ' + IsDelayS.nextArrival);
console.log('IsDelayS delay: ' + IsDelayS.delay);
});
The tests prior to my console.log()s are all passing, but every console.log() is turning up undefined. Also, the script that's actually being called by my React components is coming up with the same results. I have my component set to render null if these variables aren't defined, and that's exactly what's happening.
Any help with understanding this is greatly appreciated.
You do not set the modules correctly, when setting a member value you should mutate the object, now you just set a variable value.
The following should work for you:
var module = (function(){
const ret = {
mutateSomething:function(value){
//set otherValue on the object returned (mutate ret)
ret.otherValue = value;
}
,otherValue:undefined
};//create the object first
return ret;//then return the object
}())//IIFE
console.log("before mutate:",module.otherValue);
module.mutateSomething("Hello World");
console.log("after mutate:",module.otherValue);

Module not found with npm package in React app

I have a React app that takes some data from an API. The data is transit data and is serialized with protocol buffers, so I'm using the gtfs-realtime-bindings.js package to deserialize it. That also uses ProtoBuf.js and ByteBuffer.js under the hood. However, when I run my dev server, I'm getting this error in the browser:
./node_modules/protobufjs/ProtoBuf.js
Module not found: `/Users/Ben/React/subway-
checker/node_modules/ByteBuffer/ByteBuffer.js` does not match the
corresponding path on disk `bytebuffer`.
I'm not really sure how to start debugging this. It could be a Webpack issue? I'm using create-react-app if that helps diagnose.
For context, here's the rest of the code in the file that's causing the error:
import GtfsRealtimeBindings from 'gtfs-realtime-bindings';
import request from 'request';
function getFeedData (sub) {
var feedId;
switch (sub) {
case '1' || '2' || '3' || '4' || '5' || '6' || 'S':
feedId = 1;
break;
case 'A' || 'C' || 'E':
feedId = 26;
break;
case 'N' || 'Q' || 'R' || 'W':
feedId = 16;
break;
case 'B' || 'D' || 'F' || 'M':
feedId = 21;
break;
case 'L':
feedId = 2;
break;
case 'G':
feedId = 31;
break;
}
var requestSettings = {
method: 'GET',
uri: 'http://datamine.mta.info/mta_esi.php?key=YOUR_KEY_HERE&feed_id=2',
encoding: null
};
request(requestSettings, function (error, response, body) {
if (!error && response.statusCode == 200) {
var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
return { feed: feed };
}
});
}
function reverseStop (sub, stop) {
var stopIdN
var stopIdS
var stopData = require('./stops');
var invalidEntries = 0;
function filterByName (item) {
if (item.stop_name == stop && item.stop_id.charAt(0) == sub) {
return true;
}
invalidEntries++;
return false;
}
var stopObjs = stopData.filter(filterByName);
for (var i = 0; i < stopObjs.length; i++) {
if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'N') {
stopIdN = stopObjs[i].stop_id;
} else if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'S') {
stopIdS = stopObjs[i].stop_id;
}
}
return {
stopIdN: stopIdN,
stopIdS: stopIdS
};
}
var isDelayN = (function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(sub, stop);
getFeedData(sub);
(function () {
var invalidEntries = 0;
var feedObjs = getFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdN) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs.length; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
})();
var nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
})();
var isDelayS = (function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(stop);
getFeedData(sub)
.then(function (feed) {
var invalidEntries = 0;
var feedObjs = feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdS) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
});
var nextArrival = Math.min(...arrivals);
var delayInex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
})();
export { isDelayN, isDelayS };
I realize that code may need a lot of context. In lieu of posting all of my components and having an unreasonably long post, here's the full Github repo as it stands right now: https://github.com/benuchadnezzar/subway-checker
Any help is appreciated! Including if you see something else egregiously wrong with the code in this file.

Javascript: Updating direction of robot using string is not working

Javascript
Trying to work on a simple game of moving a robot using key L(to move left), R(to move right), F(to move forward) from a specific position on a board where it is created using 5x5 dimension and always facing North (shown as N). Clicking a Move button after entering any of above string/characters should display the current position.
Expected: For instance if I say board dimension (5x5), current position (3,3), enter 'R' and hit Move button it should show the resulting position as (3,3) E because the robot was facing north (N) first and now asked to move to RIGHT which would be east (E).
Problem: Can't seem to spot the issue in my code why the direction is not getting updated.
Here is the code that does all calculation and update.
var RobotManager = {
roomType: 'square',
roomParameters: [5, 5],
robotDirection: 'N',
robotPosition: [1, 2],
possibleDirections: ["N", "E", "S", "W"],
errorMessageNumber: -1,
errorMessage: [
"error0",
"error1",
"all other errors removed to keep code clean"
],
squares: [],
stringCommandThatExexuted: '',
init: function() {
var regexp_number = /^[1-9]$|([1][0-9])$/;
return true;
},
// This should move the robot to the right direction
turnRight: function() {
var movePosition = this.possibleDirections.indexOf(this.robotDirection);
if (movePosition == this.possibleDirections.length - 1) {
return this.possibleDirections[0];
}
return this.possibleDirections[movePosition + 1];
},
turnLeft: function() {
var movePosition = this.possibleDirections.indexOf(this.robotDirection);
if (movePosition == 0) {
return this.possibleDirections[this.possibleDirections.length - 1];
}
return this.possibleDirections[movePosition - 1];
},
moveForward: function() {
var nextPosition = this.getNextPosition();
var nextSquare = {
X: nextPosition[0],
Y: nextPosition[1]
};
if (this.isSquareAvailable(nextSquare)) {
this.robotPosition = nextPosition;
} else {
this.errorMessageNumber = 1;
return false;
}
return true;
},
//this is not getting executed to update the direction
getNextPosition: function() {
var x, y;
switch (this.robotDirection) {
case "N":
x = this.robotPosition[0];
y = this.robotPosition[1] - 1;
break;
case "E":
x = this.robotPosition[0] + 1;
y = this.robotPosition[1];
break;
case "W":
x = this.robotPosition[0] - 1;
y = this.robotPosition[1];
break;
case "S":
y = this.robotPosition[1] + 1;
x = this.robotPosition[0];
break;
}
return [x, y];
},
//First button clicks comes here and just renders default value of direction
getRobotsPositionAndDirection: function() {
if (this.errorMessageNumber <= 1) {
var message = "";
if (this.errorMessageNumber == 0) {
return this.errorMessage[0];
}
if (this.errorMessageNumber == 1) {
message = this.errorMessage[1];
}
return message + this.robotPosition[0] + " " + this.robotPosition[1] + " " + this.robotDirection;
}
return this.errorMessage[8];
},
checkCommandString: function(string) {
var english_command = /^[LRF]*$/;
if (english_command.test(string)) {
return true;
}
this.errorMessageNumber = 0;
return false;
},
getCommandStringThatExecuted: function() {
return this.stringCommandThatExexuted;
},
//This is where index is passed as 0 and doesn't execute
moveRobotToOnePosition: function(letter) {
switch (letter) {
case 'L':
this.robotDirection = this.turnLeft();
this.stringCommandThatExexuted += 'L';
break;
case 'R':
this.robotDirection = this.turnRight();
this.stringCommandThatExexuted += 'R';
break;
case 'F':
if (this.moveForward()) {
this.stringCommandThatExexuted += 'F';
return true;
} else {
return false;
}
break;
}
},
moveRobot: function(string) {
string = string.toUpperCase();
if (this.checkCommandString(string)) {
var array = string.split('');
for (var i = 0; i < array.length; i++) {
return this.moveRobotToOnePosition(i);
}
return true;
}
this.errorMessageNumber = 0;
}
}
So your problem is actually pretty simple, and my apologies for taking so long to figure this out. The issue is that you were passing the array index and not the array element.
moveRobot: function(string) {
string = string.toUpperCase();
if (this.checkCommandString(string)) {
var array = string.split('');
for (var i = 0; i < array.length; i++) {
// return this.moveRobotToOnePosition(i);
this.moveRobotToOnePosition(array[i]); // don't use return here unless you want to exit the function.
}
return true;
}
this.errorMessageNumber = 0;
}

making an array of custom objects with default values in JavaScript

So what I'm trying to do is an array of custom objects. So I have a constructor, but I don't pass values through parameters, rather I want to initialise all to 0 and the use getters or setters to retrieve them. Obviously, it doesn't work but I don't know why. Everywhere I looked the object were created by passing values through parameters, so I just guessed.
My constructor
function Stol()
{
var cipsy = 0, kofca = 0, dzus = 0, sypcaj = 0, vrecaj = 0, coko = 0,jedlo = 0, pernik = 0, kava = 0, ucet = 0;
this.cipsy = cipsy;
this.kofca = kofca;
this.dzus = dzus;
this.sypcaj = sypcaj;
this.vrecaj = vrecaj;
this.coko = coko;
this.jedlo = jedlo;
this.pernik = pernik;
this.kava = kava;
this.ucet = ucet;
this.reset = reset;
function reset() {
this.cipsy = 0;
this.kofca = 0;
this.dzus = 0;
this.sypcaj = 0;
this.vrecaj = 0;
this.coko = 0;
this.jedlo = 0;
this.pernik = 0;
this.kava = 0;
Obrat += this.ucet;
this.ucet = 0;
}
this.addItem = addItem;
function addItem(type, number) {
switch (type) {
case 0 : this.cipsy += number; break;
case 1 : this.kofca += number; break;
case 2 : this.dzus += number; break;
case 3 : this.sypcaj += number; break;
case 4 : this.vrecaj += number; break;
case 5 : this.coko += number; break;
case 6 : this.jedlo += number; break;
case 7 : this.pernik += number; break;
case 8 : this.kava += number; break;
}
}
this.getItem = getItem;
function getItem(type) {
var item;
switch (type) {
case 0 : item = this.cipsy; break;
case 1 : item = this.kofca; break;
case 2 : item = this.dzus; break;
case 3 : item = this.sypcaj; break;
case 4 : item = this.vrecaj; break;
case 5 : item = this.coko; break;
case 6 : item = this.jedlo; break;
case 7 : item = this.pernik; break;
case 8 : item = this.kava; break;
}
return item;
}
}
then here I create the Array
var stol = new Array();
for (var i = 0; i < 14; i++) {
stol[i] = new Stol();
}
and eventually I want to modify some spans using jQuery like this. #selecStol is a dropdown list (the switch is not completed).
$("#selecStol").change(function(){
var myStol = stol[$(this).find(":selected").val()];
for (i = 0; i < 14; i++) {
switch (i) {
case 0 : $("#cipsy").text(myStol.getItem(i));break;
}
}
})
But it doesn't work, and I don't know which part.
That is because this in your getter function isn't what you think.
If you check the this in a dev tool, you'll probly see the window object. To solve that, you can either save the this in a var like that :
function Stol(){
var self = this;
//All your variable "this"
this.getItem = function(type){
//In this function you use self instead of this
//ex : case 0 : item = self.cipsy; break;
}
}
Or the recommanded way, using prototype :
function Stol(){
//Your things
}
Stol.prototype.getItem = function(type){
//Now "this" will be Stol object.
}
Note that i've only used getItem function for the answer, but all your others function have the same problem.

Categories

Resources