Skip to content

Instantly share code, notes, and snippets.

@JDMcKinstry
Created February 26, 2016 15:34
Show Gist options
  • Save JDMcKinstry/eac8e69e123434993c20 to your computer and use it in GitHub Desktop.
Save JDMcKinstry/eac8e69e123434993c20 to your computer and use it in GitHub Desktop.
Converts a String into an Array of Numbers
if (Object['defineProperty'] && !String.prototype.hasOwnProperty('toIntArry')) Object.defineProperty(String.prototype, "toIntArry", {
// b = split character/phrase
// c = boolean wether to keep periods or not
value: function(b, d) {
b || (b = "");
var a = this.split(b), c;
for (c in a) a[c] = parseFloat(a[c].replace(d ? /[^0-9|.]/g : /[^0-9]/g, "").replace(/^0+/g, ""));
return a.filter(function(a) { return a === a })
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment