Skip to content

Instantly share code, notes, and snippets.

const createScript = (path, version) => {
const scriptTag = document.createElement('script')
scriptTag.src = path + '?v=' + version
scriptTag.type = 'text/javascript'
document.head.appendChild(scriptTag)
}
const createStyle = (path, version) => {
@nwrox
nwrox / convert-dec-bin.js
Last active July 6, 2017 13:14
Desafio decimal para binário
const getLog2 = (n) => Math.round(Math.log2(n))
const reverseSeq = (n) => Array.from(Array(n + 1).keys()).reverse()
const getPow = (b, n) => Math.pow(b, n)
const decToBin = (n) => {
reverseSeq(getLog2(n)).reduce(
(acc, curr) => (getPow(2, curr) <= n) ? ( n -= getPow(2, curr), acc + '1' ) : acc + '0', ''
)