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

Version Path
trackler-2.2.1.17 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.16 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.15 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.14 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.13 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.12 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.11 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.10 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.9 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.8 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.7 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.6 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.5 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.4 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.3 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.2 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.1 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.0 tracks/javascript/exercises/diamond/example.js
trackler-2.2.0.6 tracks/javascript/exercises/diamond/example.js
trackler-2.2.0.5 tracks/javascript/exercises/diamond/example.js