Created
February 20, 2018 15:13
-
-
Save devNoiseConsulting/7c1c03e92e2063b7bde14e27504acb88 to your computer and use it in GitHub Desktop.
Draw Doodle - PhillyDev Slack #daily_programmer - 20180220
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
| const drawDoodle_1 = function(doodle) { | |
| doodle = doodle.split(''); | |
| doodle = doodle.map((v, i) => { | |
| const padding = new Array(i).fill(' '); | |
| return padding.concat([v]).join(''); | |
| }); | |
| return doodle.join('\n'); | |
| }; | |
| const drawDoodle_2 = function(doodle) { | |
| return doodle | |
| .split('') | |
| .map((v, i) => { | |
| const padding = new Array(i).fill(' '); | |
| return padding.concat([v]).join(''); | |
| }) | |
| .join('\n'); | |
| }; | |
| // Third solution based off of casiotone's solution. | |
| const drawDoodle_3 = function(doodle) { | |
| return doodle | |
| .split('') | |
| .map((v, i) => `${' '.repeat(i)}${v}`) | |
| .join('\n'); | |
| }; | |
| let drawDoodle = drawDoodle_3; | |
| // Doing tricky things because javascript want to escape the '\' | |
| // so '\\\\\\\\\\\' is a bad string. | |
| let test = '\\'.repeat(11); | |
| let 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