Skip to content

Instantly share code, notes, and snippets.

@q-ode
Created July 17, 2017 14:58
Show Gist options
  • Save q-ode/bc9fbd16ec32281d581ea4e7b42f73f4 to your computer and use it in GitHub Desktop.
Save q-ode/bc9fbd16ec32281d581ea4e7b42f73f4 to your computer and use it in GitHub Desktop.
Weifund.js
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