Created
August 26, 2017 14:53
-
-
Save rogeercruz/ac70060d10ccb36acdd8ca1c39b6ffaa to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/bozujenuka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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