Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue