Vector array - Node.js Data Structure

Node.js examples for Data Structure:Vector

Description

Vector array

Demo Code


Array.prototype._vectorize = function(other, y, z, w) {
  var result = [], i;
  if (typeof(other) == 'number') {
    if (typeof(y) == "undefined") { other = [other]; }
    else if (typeof(z) == "undefined") { other = [other, y]; }
    else if (typeof(w) == "undefined") { other = [other, y, z]; }
    else { other = [other, y, z, w]; }/*from   ww w.j a  va  2 s  . co  m*/
  }
  
  if (other.length == 1)
    for (i = 0; i < this.length; i++) result[i] = other[0];
  else if (other.length == this.length)
    for (i = 0; i < this.length; i++) result[i] = other[i];
  else throw new Error("Argument must be a scalar value or a vector of equal dimensions; received "+other.toSource()+" for "+this.toSource());

  return result;
};

Related Tutorials