Last active
August 3, 2021 13:33
-
-
Save recscse/30aa0416735f5adf174cf682165b8149 to your computer and use it in GitHub Desktop.
Print the binary number JS Bin// source https://jsbin.com/sebayix
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 name="description" content="conver the number into binary till array length"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function powerSet(arr){ | |
var power = []; | |
let total = Math.pow(2,arr.length); | |
for(let i=0;i<total;i++){ | |
var tempset = []; | |
var num = i.toString(2); | |
while(num.length < arr.length){ | |
num = "0"+num; | |
} | |
console.log(num); | |
} | |
} | |
let arr = [1,2,3]; | |
powerSet(arr); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function powerSet(arr){ | |
var power = []; | |
let total = Math.pow(2,arr.length); | |
for(let i=0;i<total;i++){ | |
var tempset = []; | |
var num = i.toString(2); | |
while(num.length < arr.length){ | |
num = "0"+num; | |
} | |
console.log(num); | |
} | |
} | |
let arr = [1,2,3]; | |
powerSet(arr);</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
function powerSet(arr){ | |
var power = []; | |
let total = Math.pow(2,arr.length); | |
for(let i=0;i<total;i++){ | |
var tempset = []; | |
var num = i.toString(2); | |
while(num.length < arr.length){ | |
num = "0"+num; | |
} | |
console.log(num); | |
} | |
} | |
let arr = [1,2,3]; | |
powerSet(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment