Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Please insert list as an array! e.g. [1,2,3]</h1>
<input id="userInput"></input>
<button id="button">submit</button>
<p id="output"></p>
              
            
!

CSS

              
                
              
            
!

JS

              
                
document.getElementById("button").addEventListener("click",function(){
var arr = eval(document.getElementById("userInput").value);

var finalPlaces = [];
var switchesNum = [];
var digitNum = [];
var counter = 0;

var totalNum = 2**arr.length;

//appends values to switchesNum and digitNum, which will be used in generating the 0,1 patterns
for (h=1;h<=arr.length;h++){
  switchesNum[arr.length-h]=(2**(h-1));
  digitNum[arr.length-h]=(totalNum/(2**h));
}

//creates 0,1 pattern that will dictate whether a character is to be shown or not, and appends 0,1 pattern to finalPlaces array
for (i=0;i<arr.length;i++){
  if (i==0){
    for (j=0;j<switchesNum[i];j++){
      for (k=0;k<digitNum[i];k++){
        finalPlaces.push("1")
      }
      for (l=0;l<digitNum[i];l++){
        finalPlaces.push("0")
      }
    }    
  } else {
    counter = 0;
    for (m=0;m<switchesNum[i];m++){
      for (n=0;n<digitNum[i];n++){
        finalPlaces[counter]="1"+String(finalPlaces[counter]);
        counter=counter+1;
      }
      for (o=0;o<digitNum[i];o++){
        finalPlaces[counter]="0"+String(finalPlaces[counter]);
        counter=counter+1;
      }
    } 
  }
};

var finalOutput = [];

//creates elements in the finalOutput array that will be edited
for (r=0;r<totalNum;r++){
  finalOutput.push("");
}

//edits elements in finalOutput array to be outputted, based on finalPlaces 0,1 pattern
for (p=0;p<totalNum;p++){
  for (q=0;q<arr.length;q++){
    if (finalPlaces[p].charAt(q)=="1"){
      finalOutput[p]=finalOutput[p]+arr[q];
    } else {
      finalOutput[p]=finalOutput[p];
    }
  }
}




  document.getElementById("output").innerHTML=finalOutput;
},false)
//////////////redo to make them all arrays within final array??? so that there are commas in between numbers + alert displays square brackets
/////////////also output as headers 
              
            
!
999px

Console