I hereby claim:
- I am luqih on github.
- I am lucasjanon (https://keybase.io/lucasjanon) on keybase.
- I have a public key whose fingerprint is 136F 8334 AF90 55DD 3513 6A0F 910C D2A6 3691 CAA4
To claim this, I am signing this object:
const fn = (fnParam) => { | |
if (!fnParam) throw new Error('Missing fnParam') | |
... | |
} |
const claimMissing = require('./utils/claimMissing') | |
const fn = (importantParam = claimMissing('importantParam')) => { | |
console.log(importantParam) | |
} | |
fn() // Error: Missing importantParam | |
fn('hello world') // hello world |
module.exports = (paramName) => { | |
throw new Error(`Missing ${paramName}`) | |
} |
// Adds a .catch to the express callback to handle errors that happen in async/await functions | |
// you should wrap every route with this handler | |
// ie: errorHandler((req, res) => res.send(JSON.stringify(res.locals.user))) | |
const errorHandler = fn => (req, res, next) => { | |
Promise.resolve(fn(req, res, next)) | |
.catch(error => { | |
if (process.NODE_ENV === 'development') console.log(require('util').inspect(error)) | |
next(error) | |
}) | |
} |
const arr = [9, 90, 95, 99, 50, 5, 56, 504, 5006, 544, 1] | |
const highestCombination = (a) => { | |
const grouped = a.reduce( | |
(acc, c) => { | |
const cInitial = `${c}`.split('')[0] | |
acc[cInitial] ? | |
acc[cInitial].items.push(c) | |
: | |
acc[cInitial] = { items: [c], longest: 0 } |
I hereby claim:
To claim this, I am signing this object:
class MinHeap { | |
constructor ({ items } = {}) { | |
this.heap = items ? [...items] : [] | |
this.length = this.heap.length | |
} | |
get () { | |
return this.heap | |
} |
/** | |
* The logic is the following: first call: no parents, then the node can have any value | |
* then it goes down recursively on both left and right nodes, checking that left.value < node.value & right.value > node.value | |
* but the magic is the following, and it's where most algorithms fail (or use much more computation than this one): | |
* in the recursive call involving the left node, the algorithm sets a maximum value to subsequent recursive calls, so when the left node | |
* calls validateTree on its right node, that right node is forced to not just being higher than its parent but also | |
* being lower than the parent of its parent, because remember that a binary search tree can't have any direct or indirect higher value | |
* on its left. The same logic is applied to its right, but of course with a minimum value. | |
*/ | |
const validateTree = (node, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) => { |
{"lastUpload":"2020-04-04T18:58:21.162Z","extensionVersion":"v3.4.3"} |
const numberAsUsd = price => price.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); // numberAsUsd(1000) === 1,000 | |
const usdToArs = price => price.replace(/[,.]/g, x => (x === ',' ? '.' : ',')); // usdToArs(1,000) === 1.000 | |
const deleteZerosAfterComma = price => price.replace(',00', ''); // deleteZerosAfterComma(1.000,00) === 1.000 | |
export const numberAsArs = price => `$ ${deleteZerosAfterComma(usdToArs(numberAsUsd(price)))}`; // numberAsArs(1000) === '$ 1.000' |