-
Notifications
You must be signed in to change notification settings - Fork 29
wayoutmind edited this page Apr 27, 2013
·
1 revision
// List of numbers
var set = new gauss.Vector(5, 1, 3, 2, 21);
// From a regular Array
var numbers = new gauss.Vector([8, 6, 7, 5, 3, 0, 9]);
// Convert an Array to a Vector with helper method toVector()
var vanilla = [4, 1, 2, 5, 6];
var chocolate = vanilla.toVector();
// After instantiation, Gauss objects can be conveniently used like any Array
numbers[0] = 2;
set[1] = 7;
Note: To prevent unintended scope/prototype pollution, Gauss versions after 0.2.3 have removed support for monkey patching the native Array data type. Use the .toArray() method of any Gauss object to a convert to a vanilla Array. Gauss adds a toVector() convenience method to the Array prototype to facilitate converting to Vectors.
All of Gauss's methods accept an optional callback:
set.min();
set.min(function(result) {
result / 2;
/* Do more things with the minimum*/
});
In addition, for methods that return another Vector, method chaining makes it easy to perform calculations that flow through each other:
set.quantile(4).stdev(); // Find the standard deviation of data set's quartiles
Finally, you can mix and match both callbacks and chaining:
set.quantile(4).stdev(function(stdev) {
if (stdev > 1) {
/* Do something awesome */
}
});