This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function foo() { | |
try { | |
const { pointer_id } = await db('pointer') | |
.where({ report: 'foo-report' }) | |
.first(); | |
const data = await db('data').where('id', '>', pointer_id); | |
const report = makeReport(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function abstraction of try/catch | |
const fetch = () => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
const fn = Math.floor(Math.random() * 2) % 2 ? resolve : reject; | |
fn('Foo'); | |
}, 100); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function abstraction of try/catch | |
const fetch = () => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
const fn = Math.floor(Math.random() * 2) % 2 ? resolve : reject; | |
fn('Foo'); | |
}, 100); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const foo = (str, res = '') => (Number.isNaN(Number.parseInt(str[0], 10)) | |
? res | |
: foo(str.slice(1), res + str[0])); | |
console.log(foo('4528 Date: ORDER')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda'); | |
const xs = [ | |
{ | |
agent: 'Kim', ring_time: 1, queue_id: 1, talk_time: 0, | |
}, | |
{ | |
agent: 'Frank', ring_time: 1, queue_id: 1, talk_time: 0, | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xs = [ | |
{ | |
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0, | |
}, | |
{ | |
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0, | |
}, | |
{ | |
agent: 'Kayla', ring_time: 1, queue_id: 1, talk_time: 1, | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function splitEvery(n, arr) { | |
const res = []; | |
let i = 0; | |
while (i < arr.length) { | |
res.push(arr.slice(i, i += n)); | |
} | |
return res; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Recursive promises | |
const resolvePromises = (promises, result = []) => { | |
if (!promises.length) { | |
return Promise.resolve(result); | |
} | |
return promises[0] | |
.then((response) => resolvePromises(promises.slice(1), result.concat(response))); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda'); | |
const userRegAttrs = [ | |
{ reg_id: 1, attr_name: 'foo', attr_value: 1 }, | |
{ reg_id: 1, attr_name: 'bar', attr_value: 3 }, | |
]; | |
const user_id = 1; | |
const res = userRegAttrs.map((obj) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda'); | |
const userRegAttrs = [ | |
{ reg_id: 1, attr_name: 'foo', attr_value: 1 }, | |
{ reg_id: 1, attr_name: 'bar', attr_value: 3 }, | |
]; | |
const user_id = 1; | |
const res = R.pipe( |