Last active
November 14, 2018 03:08
-
-
Save talitaoliveira/4fba10b9454d88697541e347debfa7cb to your computer and use it in GitHub Desktop.
Using String padding - ES8 (padStart and padEnd) by length of previous line.
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 firstLine = '======================================================='; | |
const lastLine = firstLine; | |
const lenghtLines = firstLine.length; | |
let welcomeText = '⭐️ Hello World! Webpack + Babel! ⭐️'; | |
const lengthText = welcomeText.length; | |
const leftToComplete = lenghtLines - lengthText; | |
const halfComplete = leftToComplete/2; | |
welcomeText = welcomeText.padStart(lenghtLines-halfComplete, '~'); | |
welcomeText = welcomeText.padEnd(lenghtLines, '~'); | |
console.log(` | |
${firstLine} | |
${welcomeText} | |
${lastLine} | |
`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment