Skip to content

Instantly share code, notes, and snippets.

@rogeercruz
Created August 26, 2017 14:53
Show Gist options
  • Save rogeercruz/ac70060d10ccb36acdd8ca1c39b6ffaa to your computer and use it in GitHub Desktop.
Save rogeercruz/ac70060d10ccb36acdd8ca1c39b6ffaa to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/bozujenuka
<!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">
var toBinary = function(number, array = []) {
var quotient = Math.trunc(number/2);
var remainder = number % 2;
if (quotient > 1 ){
array.unshift(remainder)
return toBinary(quotient, array);
}
array.unshift(remainder);
array.unshift(quotient);
return array.join("");
}
//console.log(toBinary(6))
array = [ 1, 2 ,3 ,4 ,5];
console.log(array.reverse())
</script>
<script id="jsbin-source-javascript" type="text/javascript">var toBinary = function(number, array = []) {
var quotient = Math.trunc(number/2);
var remainder = number % 2;
if (quotient > 1 ){
array.unshift(remainder)
return toBinary(quotient, array);
}
array.unshift(remainder);
array.unshift(quotient);
return array.join("");
}
//console.log(toBinary(6))
array = [ 1, 2 ,3 ,4 ,5];
console.log(array.reverse())
</script></body>
</html>
var toBinary = function(number, array = []) {
var quotient = Math.trunc(number/2);
var remainder = number % 2;
if (quotient > 1 ){
array.unshift(remainder)
return toBinary(quotient, array);
}
array.unshift(remainder);
array.unshift(quotient);
return array.join("");
}
//console.log(toBinary(6))
array = [ 1, 2 ,3 ,4 ,5];
console.log(array.reverse())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment