Permalink
Browse files

new Array() --> []

  • Loading branch information...
1 parent e3d1091 commit 741cf922da76bcade002966b46fef4f2712fcf35 Philmod committed Nov 1, 2012
Showing with 9 additions and 9 deletions.
  1. +9 −9 lib/kmeans.js
View
@@ -109,11 +109,11 @@ clusterize.prototype.checkV = function(v) {
* Initialize the groups arrays
*/
clusterize.prototype.initialize = function() {
- this.groups = new Array();
+ this.groups = [];
for (var i=0, max=this.k; i<max; ++i) {
this.groups[i] = new Group(this);
}
- this.indexes = new Array(); // used to choose randomly the initial centroids
+ this.indexes = []; // used to choose randomly the initial centroids
for (var i=0, max=this.v.length; i<max; ++i) {
this.indexes[i] = i;
}
@@ -148,7 +148,7 @@ clusterize.prototype.clustering = function() {
*/
clusterize.prototype.output = function() {
- var out = new Array();
+ var out = [];
for (var j=0, max=this.groups.length; j<max; ++j) {
out[j] = _.pick(this.groups[j],'centroid','cluster','clusterInd');
}
@@ -186,8 +186,8 @@ function Group() {
*/
Group.prototype.initCluster = function() {
- this.cluster = new Array(); // dimensions
- this.clusterInd = new Array(); // index
+ this.cluster = []; // dimensions
+ this.clusterInd = []; // index
}
@@ -198,15 +198,15 @@ Group.prototype.initCluster = function() {
*/
Group.prototype.defineCentroid = function(self){
- this.centroidOld = (this.centroid) ? this.centroid : new Array();
+ this.centroidOld = (this.centroid) ? this.centroid : [];
if (this.centroid && this.cluster.length>0) {
this.calculateCentroid();
}
else { // random selection
var i = Math.floor(Math.random() * self.indexes.length);
this.centroidIndex = self.indexes[i];
self.indexes.splice(i,1);
- this.centroid = new Array();
+ this.centroid = [];
if (!_.isArray(self.v[this.centroidIndex])) { // only one dimension
this.centroid[0] = self.v[this.centroidIndex];
}
@@ -227,7 +227,7 @@ Group.prototype.defineCentroid = function(self){
*/
Group.prototype.calculateCentroid = function() {
- this.centroid = new Array();
+ this.centroid = [];
for (var i=0; i<this.cluster.length; ++i) { // loop through the cluster elements
for (var j=0, max=this.cluster[i].length; j<max; ++j) { // loop through the dimensions
this.centroid[j] = (this.centroid[j]) ? this.centroid[j]+this.cluster[i][j] : this.cluster[i][j];
@@ -245,7 +245,7 @@ Group.prototype.calculateCentroid = function() {
*/
Group.prototype.distanceObjects = function(self) {
- if (!this.distances) this.distances = new Array();
+ if (!this.distances) this.distances = [];
for (var i=0, max=self.v.length; i<max; ++i) {
this.distances[i] = distance(this.centroid, self.v[i]);
}

0 comments on commit 741cf92

Please sign in to comment.