Skip to content

Instantly share code, notes, and snippets.

@pirhoo
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save pirhoo/9132917 to your computer and use it in GitHub Desktop.

Select an option

Save pirhoo/9132917 to your computer and use it in GitHub Desktop.
dojo-kata-2
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