Advertisement
BumbleguppysRevenant

Star tree

Mar 4th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tree(height, rightAlign)
  2.     {  
  3.        var starArr = [String.fromCharCode(9733)]; // Unicode Star character, Opera renders it a little smaller than IE and FF
  4.        var pad = String.fromCharCode(8195); //Ascii EM space
  5.        var i;
  6.  
  7.        for(i = 1; i < height; i++)
  8.        {
  9.            starArr.push(starArr[i - 1] + starArr[i - 1]);
  10.            pad += pad;
  11.        }
  12.  
  13.        if(rightAlign)
  14.        {
  15.           for(i = 0; i < height; i++)
  16.           {
  17.              starArr[i] = pad.substr(starArr[i].length, pad.length - 1) + starArr[i];
  18.           }
  19.        }
  20.        
  21.        return starArr.join('\n');
  22.     }
  23.  
  24.     alert(tree(4, true));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement