Skip to content

Instantly share code, notes, and snippets.

@recscse
Last active August 3, 2021 13:33
Show Gist options
  • Save recscse/30aa0416735f5adf174cf682165b8149 to your computer and use it in GitHub Desktop.
Save recscse/30aa0416735f5adf174cf682165b8149 to your computer and use it in GitHub Desktop.
Print the binary number JS Bin// source https://jsbin.com/sebayix
<!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>
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