Skip to content

Instantly share code, notes, and snippets.

@devNoiseConsulting
Last active February 23, 2018 21:19
Show Gist options
  • Select an option

  • Save devNoiseConsulting/23b528e9da503f65eb4b3f931b056b60 to your computer and use it in GitHub Desktop.

Select an option

Save devNoiseConsulting/23b528e9da503f65eb4b3f931b056b60 to your computer and use it in GitHub Desktop.
Draw Doodle II - PhillyDev Slack #daily_programmer - 20180221
// 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