Skip to content

Instantly share code, notes, and snippets.

const chai = require('chai');
const expect = chai.expect;
const chaiThings = require('chai-things');
const chaiSpies = require('chai-spies');
const sinon = require('sinon');
chai.use(chaiThings);
chai.use(chaiSpies);
// Models
const db = require('../server/models');
utils.throttle = (func, delay) => {
function throttledFunc(...args) {
setTimeout(function () {
func(...args)
}, delay);
}
return throttledFunc;
};
module.exports = utils;
function buildGraph(edges) {
let graph = Object.create(null);
function addEdge(from, to) {
if (graph[from] == null) {
graph[from] = [to];
} else {
graph[from].push(to);
}
console.log(from, to);
console.log(graph[from]); //vs console.log(graph); why does printing the entire graph here print the completed graph on the second call, even though it shouldn't be fully constructed until the last call?
const numberToEnglish = n => {
//handle exceptions; zero, >/< prescribed range, non-integers
if (n === 0)
return 'zero';
if (n < 0 || n > 99999)
return '';
let strn = String(n).padStart(5,'0'); //convert to uniform, five digit string
if (strn.includes('.'))
return '';
//get strings for thousands, hundreds, and tens