Last active
February 23, 2018 21:19
-
-
Save devNoiseConsulting/23b528e9da503f65eb4b3f931b056b60 to your computer and use it in GitHub Desktop.
Draw Doodle II - PhillyDev Slack #daily_programmer - 20180221
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
| // Third solution based off of casiotone's solution. | |
| const drawDoodle = function(doodle) { | |
| let padSize = 0; | |
| return doodle | |
| .split('') | |
| .map(v => { | |
| padSize = v == '/' ? padSize - 1 : padSize; | |
| padSize = padSize < 0 ? 0 : padSize; | |
| let padding = padSize; | |
| padSize = v == '\\' ? padSize + 1 : padSize; | |
| return `${' '.repeat(padding)}${v}`; | |
| }) | |
| .join('\n'); | |
| }; | |
| let test = '\\\\\\//\\\\/\\//\\\\///'; | |
| let result = drawDoodle(test); | |
| console.log(test); | |
| console.log(result); | |
| test = '\\/\\/\\/'; | |
| result = drawDoodle(test); | |
| console.log(test); | |
| console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment