Skip to content

Instantly share code, notes, and snippets.

View chvonrohr's full-sized avatar

Christian von Rohr chvonrohr

  • Lucerne, Switzerland
View GitHub Profile
@chvonrohr
chvonrohr / js-snippets.js
Created June 17, 2019 16:35
found cool JS snippets
// 123456789 -> 123,456,789
n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
@chvonrohr
chvonrohr / shorthanders.js
Created June 19, 2019 07:06
Shorthanders
// #1 - for
let images = [ 'test.jpg', 'dummy.gif' ];
for (let i = 0; i < allImgs.length; i++) {} // long
for (let i of allImgs) { } // short
// #2 - decimal base
1000000 === 1e6
// #3 - default parameters
volume = (l, w = 3, h = 4 ) => (l * w * h);
// helper functions
const compose = (...fns) => x => fns.reduceRight((res, fn) => fn(res), x);
const tap = f => x => { f(x); return x; };
const trace = label => tap(console.log.bind(console, label + ':'));
// container helpers
const isFunction = fn => fn && Object.prototype.toString.call(fn) === '[object Function]';
const isAsync = fn => fn && Object.prototype.toString.call(fn) === '[object AsyncFunction]';