Created
August 22, 2012 17:22
-
-
Save theskumar/3427715 to your computer and use it in GitHub Desktop.
js: split_to_array()
This file contains hidden or 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 split_to_array (body, chunklen) { | |
| // * example 1: chunk_split('Hello world!', 1); | |
| // * returns 1: 'H*e*l*l*o* *w*o*r*l*d*!*' | |
| // * example 2: chunk_split('Hello world!', 10, '*'); | |
| // * returns 2: '["Hello worl","d!"]' | |
| chunklen = parseInt(chunklen, 10) || body.length; | |
| if (chunklen < 1) { | |
| return false; | |
| } | |
| return body.match(new RegExp(".{1," + chunklen + "}", "g")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment