Sha256: ab1f2c6a0e57e886dff96ed127ccc4d2ebf600153b0d0ccced52e30c3afaf1f8
Contents?: true
Size: 874 Bytes
Versions: 255
Compression:
Stored size: 874 Bytes
Contents
var Diamond = function() { this.makeDiamond = function(input){ var inputIndex = input.charCodeAt() - 65; var output = ""; for(var i = 0; i <= inputIndex; i++){ output += getLine(inputIndex, i); } for(var i = inputIndex - 1; i >= 0; i--){ output += getLine(inputIndex, i); } return output; } var getLine = function(inputIndex, index){ var difference = inputIndex - index; return spaceTimes(difference) + printAlphabets(index) + spaceTimes(difference) + "\n"; } var printAlphabets = function(index){ var character = 65 + index; if(index === 0){ return "A"; } else { return String.fromCharCode(character) + spaceTimes(((index - 1) * 2) + 1) + String.fromCharCode(character); } } var spaceTimes = function(times){ return " ".repeat(times); } }; module.exports = Diamond;
Version data entries
255 entries across 255 versions & 1 rubygems