Skip to content

Instantly share code, notes, and snippets.

@haskellcamargo
Created December 17, 2015 13:03
Show Gist options
  • Save haskellcamargo/423ac604f5600d355ea7 to your computer and use it in GitHub Desktop.
Save haskellcamargo/423ac604f5600d355ea7 to your computer and use it in GitHub Desktop.
String.prototype.chunkBy = function(len) {
var current = len;
var previous = 0;
var stack = [];
while (this[current]) {
if (this[current++].match(/s+/)) {
stack.push(this.substring(previous, current));
previous = current;
current += len;
}
}
stack.push(this.substr(previous));
return stack;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment