Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Last active December 16, 2015 11:09
Show Gist options
  • Save ryasmi/5425568 to your computer and use it in GitHub Desktop.
Save ryasmi/5425568 to your computer and use it in GitHub Desktop.
Turns a string into an array.
// Using func. https://gist.github.com/ryansmith94/5564105
func("toArray", function (elemDelimeter, attrDelimeter, fn) {
var i, elemArray, len;
elemArray = this.split(elemDelimeter);
len = elemArray.length;
for (i = 0; i < len; i += 1) {
elemArray[i] = elemArray[i].split(attrDelimeter);
if (fn) {
elemArray[i] = fn(elemArray[i]);
}
}
return elemArray;
}, String.prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment