home

programming

javascript

random

const rFloat = (min, max) => Math.random() * (max - min) + min
const rInt = (min, max) => ~~(Math.random() * (max - min)) + min
const rnArrEl = arr => arr[(Math.random() * arr.length) | 0]

golf

Number(x) === +x
Math.pow(x, y) === (x ** y)
Number.isInteger(x) === (x % 1 === 0)
BigInt(x) === xn

// mind the 32-bit integers ;)
Math.floor(x) === (x >> 0) === ~~x

console

console.table(['alice', 'cheshire', 'hatter'])
console.table({id: 1, item: 'teacup'})
 
let test = false
console.assert(test, 'message shows up')
test = true
console.assert(test, 'message does not show up')
 
console.time('ID')
/* do something */
console.timeEnd('ID')

resources