Created
August 7, 2012 20:37
-
-
Save gelicia/3289070 to your computer and use it in GitHub Desktop.
Miso Dataset - return an array of split dataviews based on a dataset and a column
This file contains 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
//Take in a dataset, split it up by column, return an array of split datasets | |
Miso.Dataset.prototype.splitDataSets = function(columnName){ | |
var returnArr = []; //Array of split datasets | |
var valueArr = []; //A list of distinct values from columnName | |
//Find a distinct list of values | |
this.each( | |
function(row) { | |
if (!valueArr.contains(row[columnName])) { | |
valueArr.push(row[columnName]); | |
var whereSet = this.where({ | |
rows: function(row) { | |
return row[columnName] == valueArr[valueArr.length - 1]; | |
} | |
}); | |
returnArr.push(whereSet); | |
} | |
}); | |
return returnArr; | |
} | |
Array.prototype.contains = function(toFind) { | |
for (var i = 0; i < this.length; i += 1) { | |
if (this[i] == toFind) { | |
return true; | |
} | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment