Skip to content

Instantly share code, notes, and snippets.

@devNoiseConsulting
Created February 20, 2018 15:13
Show Gist options
  • Select an option

  • Save devNoiseConsulting/7c1c03e92e2063b7bde14e27504acb88 to your computer and use it in GitHub Desktop.

Select an option

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