Created
July 17, 2017 14:58
-
-
Save q-ode/bc9fbd16ec32281d581ea4e7b42f73f4 to your computer and use it in GitHub Desktop.
Weifund.js
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
function stringToLine(sentence, charactersPerLine) { | |
const length = sentence.length; | |
let line = ''; | |
for (let i = 0; i < length; i++) { | |
line = line + sentence[i]; | |
if ((i + 1) % charactersPerLine === 0 || (length - i + 1 <= charactersPerLine)) { | |
console.log(line); | |
line = ''; | |
} | |
} | |
} | |
function stringToLineWords(sentence, charactersPerLine) { | |
const words = sentence.split(' '); | |
let line = ''; | |
for (let i = 0; i < words.length; i++) { | |
let lineLength = line.length; | |
if (lineLength + words[i].length > charactersPerLine) { | |
} else { | |
//TODO: Complete implementation | |
} | |
} | |
} | |
stringToLine('Hello World', 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment