Last active
August 29, 2015 14:25
-
-
Save mlms13/2a2c9374aa830005f01f to your computer and use it in GitHub Desktop.
It's a ferble.
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 splitIntoGroups(chunks, str) { | |
var splitAt = str.charAt(0) === '"' ? | |
// if the string starts with a quote at this point, | |
// find the next quote or the end of the string | |
str.indexOf('"', 1) > -1 ? str.indexOf('"', 1) : str.length : | |
// otherwise, break at the next space | |
str.indexOf(' ', 1) > -1 ? str.indexOf(' ', 1) : str.length, | |
word = str.substring(0, splitAt).replace('"', '').trim(); | |
if (word) chunks.push(word); | |
str = str.substring(splitAt + 1); | |
return str.length > 0 ? splitIntoGroups(chunks, str.trim()) : chunks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment