Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
12
Task/Word-wrap/JavaScript/word-wrap-1.js
Normal file
12
Task/Word-wrap/JavaScript/word-wrap-1.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function wrap (text, limit) {
|
||||
if (text.length > limit) {
|
||||
// find the last space within limit
|
||||
var edge = text.slice(0, limit).lastIndexOf(' ');
|
||||
if (edge > 0) {
|
||||
var line = text.slice(0, edge);
|
||||
var remainder = text.slice(edge + 1);
|
||||
return line + '\n' + wrap(remainder, limit);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
1
Task/Word-wrap/JavaScript/word-wrap-2.js
Normal file
1
Task/Word-wrap/JavaScript/word-wrap-2.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
console.log(wrap(text, 80));
|
||||
1
Task/Word-wrap/JavaScript/word-wrap-3.js
Normal file
1
Task/Word-wrap/JavaScript/word-wrap-3.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
console.log(wrap(text, 42));
|
||||
Loading…
Add table
Add a link
Reference in a new issue