Skip to content

Instantly share code, notes, and snippets.

@cdaz5
Created September 22, 2017 15:27
Show Gist options
  • Select an option

  • Save cdaz5/12725ebafad2d3cf2b7930cce286946d to your computer and use it in GitHub Desktop.

Select an option

Save cdaz5/12725ebafad2d3cf2b7930cce286946d to your computer and use it in GitHub Desktop.
challenge refactor
//Question 2
//g makes it global and the \b keeps it to only words that have a boundry (space between).
function cocknify(input) {
return input.replace(/\bh/g, '\`')
}
// Question 3
//refactored so the for loop doesnt have = to eliminating the need for the idx - 1
function awesomeTree(height) {
if (height === 0) {
return 0
}
let whiteSpaceCount = height
console.log(new Array(whiteSpaceCount).join(' ') + ' *|*')
for (let idx = 1; idx < height; idx++, whiteSpaceCount--) {
let str = new Array((idx) * 2).join('*')
let whiteSpace = new Array(whiteSpaceCount).join(' ')
console.log(whiteSpace + "*|" + str + "|*")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment