Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created July 12, 2013 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5985751 to your computer and use it in GitHub Desktop.
Save tmcw/5985751 to your computer and use it in GitHub Desktop.
function tokenize(x) {
var pts = [], type, num = '', nums = [], segment = [];
for (var i = 0; i < x.length; i++) {
if (x[i].match(/[A-Za-z]/)) {
nums.push(num);
if (x[i].toLowerCase() == 'z') {
pts.push(segment);
segment = [];
} else if (type) {
segment.push([type, nums.map(floatit)]);
}
type = x[i];
nums = [];
num = '';
} else if (x[i] == ' ') {
nums.push(num);
num = '';
} else {
num += x[i];
}
}
pts.push(segment);
return pts;
}
function floatit(n) {
return parseFloat(n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment