Skip to content

Instantly share code, notes, and snippets.

@Rayraegah

Rayraegah/index.html

Last active Mar 31, 2018
Embed
What would you like to do?
Decimal => Base3 JS Bin// source https://jsbin.com/dunuwik
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function base3(decimal) {
const divisor = 3;
let div = decimal
let quo
let seq = [];
if(div === 0) {
return 0
}
while(1) {
if(div === 0) {
break
}
quo = ~~(div/divisor)
seq.push(div % divisor)
div = quo
}
return ~~seq.reverse().join('')
}
console.log(base3(142))
console.log(base3(3))
console.log(base3(0))
</script>
<script id="jsbin-source-javascript" type="text/javascript">function base3(decimal) {
const divisor = 3;
let div = decimal
let quo
let seq = [];
if(div === 0) {
return 0
}
while(1) {
if(div === 0) {
break
}
quo = ~~(div/divisor)
seq.push(div % divisor)
div = quo
}
return ~~seq.reverse().join('')
}
console.log(base3(142))
console.log(base3(3))
console.log(base3(0))</script></body>
</html>
function base3(decimal) {
const divisor = 3;
let div = decimal
let quo
let seq = [];
if(div === 0) {
return 0
}
while(1) {
if(div === 0) {
break
}
quo = ~~(div/divisor)
seq.push(div % divisor)
div = quo
}
return ~~seq.reverse().join('')
}
console.log(base3(142))
console.log(base3(3))
console.log(base3(0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment