Skip to content

Instantly share code, notes, and snippets.

@mlms13
Last active August 29, 2015 14:25
Show Gist options
  • Save mlms13/2a2c9374aa830005f01f to your computer and use it in GitHub Desktop.
Save mlms13/2a2c9374aa830005f01f to your computer and use it in GitHub Desktop.
It's a ferble.
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