New answers tagged

0

getPoolBasedOnLevel() is the oddity here. There are three arrow functions doing similar jobs. Using one function with a lookup should clean things up. Effectively, each of them is doing this: const sum = list=>list.reduce((a,b)=>a+b,0) function poolTotal(champ_pool,min_cost,max_cost) { const champs_for_level = champ_pool.filter(champ=> ...


0

Somewhere in your code you should be setting the template engine and the base views path, in the likes of app.set('views', __dirname+'/views/'); app.set('view engine', 'hbs'); (I assume you have that figured out already) Having said that, you can either reference a view by its location relative to the views setting, therefore: res.render('Leagues/...


3

Let me share my async await solution for that: Because Your fetch function is pretty similar till the res.text(), I would create an own function (fetchData ) for that, what is returning a Promise, what is resolving a res.text() Now you can assign an async to your getLogsfunction Lets reorganise your code above Error handling is missing here, but take care ...


0

As was already mentioned in the comments, a switch statement could be used to clean up the sets of if statements. Another option would be to abstract the similar callback functions passed to .reduce()- perhaps using partially applied functions to accept parameters - e.g. the minimum values in conditions like currentChamp.getCost() <= 3. It seems like let ...


1

Well you're right to be concerned. Your example is essentially this function wrapCheck(check) { return { check, largeArr: Array(1000000) .fill(0) .map((_, i) => i), makeNew: function (pred) { return wrapCheck(() => check(this).filter(pred)); } ...


1

A couple of helper functions will aid in flattening your callback chain: function getConnection() { return new Promise((res, rej) => { pool.getConnection(function (err, connection) { if (err) { rej(err); } else { res(connection); } }); }); } function query(connection, sql, params) { return new Promise((res, ...


2

There is some simplification to be done. The second if statement is superfluous. I'm assuming that if .Count is not 0, then you know it's going to be >=1, so you don't need to write a second if-statement. You don't need to save variables the values of which you only use once. export const GetToken = async () => { const check = await new DB()....


3

I'm no expert in JavaScript, but it seems to me if you changed the scope of token so that it is defined at the beginning of the function and then just modify the value as necessary that you can have only one return statement after all the if statements.


0

You can use Array.prototype.reduce to group items by TAG as the key and using the relationship between PARENT_TAG and TAG. This approach will give the expected result by running the array only once. const menuConfig = [{ ID: 1,TAG: "M:A", PARENT_TAG: "MAIN", TITLE: "A Title" }, { ID: 2, TAG: "AS1", PARENT_TAG: "M:A", TITLE: "A Subtitle 1" }, { ID: ...


Top 50 recent answers are included