Skip to content

Instantly share code, notes, and snippets.

@areinmeyer
Created November 22, 2022 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save areinmeyer/fab5f10cf47f95d07c67db07db20955b to your computer and use it in GitHub Desktop.
Save areinmeyer/fab5f10cf47f95d07c67db07db20955b to your computer and use it in GitHub Desktop.
Vertical Slashes solution in node
#!/usr/bin/env node
const input = process.argv.slice(2);
const slashes = String.raw`${input[0]}`;
let output = "";
const verticalSlashes = (count, input) => {
if (input.length === 0) return "";
const currSlash = input[0]
switch (currSlash) {
case "/":
newCount = count === 0 ? 0 : count - 1
output = genOutput(newCount, currSlash)
return output + verticalSlashes(newCount, input.slice(1, input.length));
case "\\":
output = genOutput(count, currSlash)
return output + verticalSlashes(count + 1, input.slice(1, input.length));
default:
output = genOutput(count, currSlash)
return output + verticalSlashes(count + 1, input.slice(1, input.length));
}
};
const genOutput = (count, slash) => {
return " ".repeat(count) + slash + "\n";
}
console.log(verticalSlashes(0, slashes));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment