Created
September 22, 2017 15:27
-
-
Save cdaz5/12725ebafad2d3cf2b7930cce286946d to your computer and use it in GitHub Desktop.
challenge refactor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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