Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active December 24, 2023 14:29
Show Gist options
  • Save mcsee/1c4881a54286a827b8fc037fdd89722c to your computer and use it in GitHub Desktop.
Save mcsee/1c4881a54286a827b8fc037fdd89722c to your computer and use it in GitHub Desktop.
function createChristmasTree(height) {
let tree = '';
let currentFloor = 1;
while (currentFloor <= height) {
tree += ' '.repeat(height - currentFloor) + 'πŸŽ„'.repeat(currentFloor)
+ '\n';
currentFloor++;
}
return tree;
}
// The side effects are OUTSIDE the function
console.log(createChristmasTree(7));
// You can also test it
const createChristmasTree = createChristmasTree(7);
describe('createChristmasTree', () => {
it('should create a Christmas tree of the specified height', () => {
const expectedTree =
' πŸŽ„\n' +
' πŸŽ„πŸŽ„\n' +
' πŸŽ„πŸŽ„πŸŽ„\n' +
' πŸŽ„πŸŽ„πŸŽ„πŸŽ„\n' +
' πŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„\n' +
' πŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„\n' +
'πŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„\n';
const result = createChristmasTree(7);
expect(result).toEqual(expectedTree);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment