Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // {
- // id
- // created
- // employee
- // - id
- // - firstname
- // - employeeType
- // - id
- // - lastname
- // location
- // }
- const addIndent = number => [...Array(number).keys()].reduce(prev => `${prev}-`, "");
- const fn = str => {
- let indent = -1;
- let output = "";
- str.split("").filter(char => char !== " ").map(char => {
- if (char === "(") indent++;
- if (char === ")") {
- indent--;
- return;
- };
- output += ["(", ","].includes(char) ? `\n${addIndent(indent)}` : char;
- });
- console.log(output);
- };
- fn("(id,created,employee(id,firstname,employeeType(id), lastname),location)");
Add Comment
Please, Sign In to add comment