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