Skip to content

Instantly share code, notes, and snippets.

@raulpesilva
Last active October 15, 2019 15:12
Show Gist options
  • Save raulpesilva/6603a10aa3fffff314b9f06d6a2e4974 to your computer and use it in GitHub Desktop.
Save raulpesilva/6603a10aa3fffff314b9f06d6a2e4974 to your computer and use it in GitHub Desktop.
const dictionary = "abcdefghijklmnopqrstuvwxyz";
const create = letter => {
createCascate(dictionary.indexOf(letter.toLowerCase()) + 1)
};
const createCascate = (indexLetter) => {
const topDiamond = []
for (let index = 0; index < indexLetter; index++) {
const array = [...new Array(indexLetter * 2 + 1)].fill('_');
array[indexLetter + index] = dictionary[index];
array[indexLetter - index] = dictionary[index];
topDiamond.push(array.join(' '))
}
console.log(topDiamond.join('\n'))
topDiamond.pop()
console.log(topDiamond.reverse().join('\n'))
};
create("j");
// create("a");
// _ _ _ _ _ _ _ _ _ A _ _ _ _ _ _ _ _ _
// _ _ _ _ _ _ _ _ B _ B _ _ _ _ _ _ _ _
// _ _ _ _ _ _ _ C _ _ _ C _ _ _ _ _ _ _
// _ _ _ _ _ _ D _ _ _ _ _ D _ _ _ _ _ _
// _ _ _ _ _ E _ _ _ _ _ _ _ E _ _ _ _ _
// _ _ _ _ F _ _ _ _ _ _ _ _ _ F _ _ _ _
// _ _ _ G _ _ _ _ _ _ _ _ _ _ _ G _ _ _
// _ _ H _ _ _ _ _ _ _ _ _ _ _ _ _ H _ _
// _ I _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ I _
// J _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ J
// _ I _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ I _
// _ _ H _ _ _ _ _ _ _ _ _ _ _ _ _ H _ _
// _ _ _ G _ _ _ _ _ _ _ _ _ _ _ G _ _ _
// _ _ _ _ F _ _ _ _ _ _ _ _ _ F _ _ _ _
// _ _ _ _ _ E _ _ _ _ _ _ _ E _ _ _ _ _
// _ _ _ _ _ _ D _ _ _ _ _ D _ _ _ _ _ _
// _ _ _ _ _ _ _ C _ _ _ C _ _ _ _ _ _ _
// _ _ _ _ _ _ _ _ B _ B _ _ _ _ _ _ _ _
// _ _ _ _ _ _ _ _ _ A _ _ _ _ _ _ _ _ _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment