Arrays

(, en)

Ranges

function* range(start, end) {
    for (let i = start; i <= end; i++) {
        yield i;
    }
}

for (i of range(1, 5)) {
    console.log(i);
}

source

Empty or not?

if (!Array.isArray(array) || !array.length) {
  // array does not exist, is not an array, or is empty
  // ⇒ do not attempt to process array
}

source

Intersperse

const intersperse = (xs, s) => xs.reduce((acc,x)=> acc ? [...acc, s, x] : [x], null)

Use millimetres in pdfmake

const MILLIMETERS_IN_INCH = 25.4;
const POINTS_IN_INCH = 72;

function mm2pt(mm) {
  const inches = mm / MILLIMETERS_IN_INCH;
  return inches * POINTS_IN_INCH;
}