Facebook

Wednesday, January 30, 2019

Node


SI Content Description
1. const sql = connection.format("SELECT * FROM table WHERE foo = ?", ["bar"]);
console.log(sql);
Build the query before execution
2. "debug-test": "mocha --inspect-brk -t 1500" //Add above line to package.json and run
npm run debug-test
Debug test in local
3. Merge objects with key value, values being integer, sum the values
 
_ = require('lodash');
//Merge the array and sum values corresponding to same carrier
//Example: x={ abc: 1, abd: 5 }, y= { abd: 2, abe: 5 } =>{abc: 1,abd: 7, abe: 5 }
merged = _.mergeWith({ ...x }, { ...y }, (a, b) => {
    a = a && _.isNumber(parseInt(a)) ? parseInt(a) : 0;
    b = b && _.isNumber(parseInt(b)) ? parseInt(b) : 0;
    return a+b;
});

No comments:

Post a Comment