hullo all,
jslint is mad at me. i'm making a function within a loop, but i'm also not quite sure how to fix it, since it seems i would need to curry the result such that the function matches the signature expected by request for a callback as well as perform variable capture correctly or perform some other javascript devilry to simplify that.
edit: the code as it is works fine. i'd just like to know how to make it so the linter isn't made at me anymore!
the section of code looks like the following:
function func(cb) {
request({ params }, (error, response) => {
const devices = response.body;
let completedCounter = 0;
for (const device of devices) {
request({ params }, (err, response) => {
if (!err && response.statusCode === 200) {
completedCounter += 1;
if (completedCounter === devices.length) {
cb(null, "message here");
}
} else {
cb(err, "message here");
}
});
}
});
}
sorry if my terminology isn't typical javascript terminology- i'm a confused c++/python/lisp programmer outside his comfort zone!
the linter output is:
39:10 error Don't make functions within a loop no-loop-func