Last active
August 29, 2015 13:56
-
-
Save pirhoo/9132917 to your computer and use it in GitHub Desktop.
dojo-kata-2
This file contains hidden or 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
| spaces(len) { | |
| String space = ""; | |
| for(int s=0; s < len; s++) space += " "; | |
| return space; | |
| } | |
| diamond(name) { | |
| int first = name.toUpperCase().codeUnitAt(0) - 65; | |
| var lines = []; | |
| for(int c = 0; c <= first; c++) { | |
| String char = new String.fromCharCode(c+65); | |
| String line = spaces(first - c) + char; | |
| if( c > 0) line = line + spaces( (c*2)-1 ) + char; | |
| lines.insert(c, line); | |
| // Duplicate the current line | |
| if(c < first) lines.insert(lines.length-c, line); | |
| } | |
| return lines.join("\n"); | |
| } | |
| void main() { | |
| print( diamond("emily") ); | |
| print( diamond("cindy") ); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment