Created
October 12, 2018 07:16
-
-
Save ripsware/a9a7db149479b098e528a5e5a37a72b6 to your computer and use it in GitHub Desktop.
This file contains 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 lineChars = ["x", " ", "o", " "]; | |
function createLine(length, isReverse){ | |
let result = ""; | |
for(let counter = 0; counter < length; counter++){ | |
if(isReverse){ | |
result = result + lineChars[counter % lineChars.length]; | |
}else{ | |
result = lineChars[counter % lineChars.length] + result; | |
} | |
} | |
return result; | |
} | |
function buildShape(n){ | |
const max = n * 2 - 1; | |
let result = ""; | |
for(let i = 1; i <= max; i++){ | |
if(i < n){ | |
result += "".padStart(n - 1) + createLine(i); | |
}else if(i == n){ | |
result += createLine(n, true) + createLine(n - 1); | |
}else{ | |
result += "".padStart(i - n) + createLine(n - (i - n) , true); | |
} | |
result += "\n"; | |
} | |
return result; | |
} | |
(() => { | |
console.log(buildShape(20)); | |
})(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment