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.37 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.36 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.35 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.34 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.33 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.32 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.31 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.30 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.29 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.28 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.27 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.26 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.25 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.24 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.23 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.22 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.21 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.20 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.19 tracks/javascript/exercises/diamond/example.js
trackler-2.2.1.18 tracks/javascript/exercises/diamond/example.js