Nodejs Array Equal equals(array)

Here you can find the source of equals(array)

Method Source Code

/**/*from www .j  a va 2 s . com*/
 * Expand built-in Array
 */

/* Check for arrays equality */
Array.prototype.equals = function(array) {
  // check argument presence
  if (!array)
    return false;

  // compare lengths
  if (this.length != array.length)
    return false;

  for (var i = 0, l = this.length; i < l; i++) {
    // Check for nested arrays
    if (this[i] instanceof Array && array[i] instanceof Array) {
      // recurse into the nested arrays
      if (!this[i].equals(array[i]))
        return false;       
    }           
    else if (this[i] != array[i]) { 
      return false;   
    }           
  }       
  return true;
}  

module.exports = Array;

Related

  1. equals(array)
    Array.prototype.equals = function (array) {
        for(var i = 0; i < this.length; i++){
            if(this[i] != array[i]){
                return false;
        return true;
    
  2. equals(array)
    Array.prototype.equals = function (array) {
        if (!array)
            return false;
        if (this.length != array.length)
            return false;
        for (var i = 0, l=this.length; i < l; i++) {
            if (this[i] instanceof Array && array[i] instanceof Array) {
                if (!this[i].equals(array[i]))
                    return false;
    ...
    
  3. equals(array)
    Array.prototype.equals = function (array) {
        if (!array){
            return false;
        if (this.length != array.length){
            return false;
        for (var i = 0, l=this.length; i < l; i++) {
            if (this[i] instanceof Array && array[i] instanceof Array) {
    ...
    
  4. equals(array)
    Array.prototype.equals = function (array) {
        if (!array) return false;
        if (this.length != array.length) return false;
        for (var i = 0, l = this.length; i < l; i++) {
            if (this[i] instanceof Array && array[i] instanceof Array) {
                if (!this[i].equals(array[i])) {
                    return false;
            } else if (this[i] != array[i]) {
    ...
    
  5. equals(array)
    Array.prototype.equals = function (array) {
      if (!array)
        return false;
      if (this.length != array.length)
        return false;
      for (var i = 0, l=this.length; i < l; i++) {
        if (this[i] instanceof Array && array[i] instanceof Array) {
          if (!this[i].equals(array[i]))
            return false;
    ...
    
  6. equals(array)
    Array.prototype.equals = function (array) {
        if (!array)
            return false;
        if (this.length != array.length)
            return false;
        for (var i = 0; i < this.length; i++) {
            if (this[i] instanceof Array && array[i] instanceof Array) {
                if (!this[i].equals(array[i]))
                    return false;
    ...
    
  7. equals(array)
    Array.prototype.equals = function (array) {
        if (!array)
            return false;
        if (this.length != array.length)
            return false;
        for (var i = 0; i < this.length; i++) {
            if (this[i] instanceof Array && array[i] instanceof Array) {
                if (!this[i].equals(array[i]))
                    return false;
    ...
    
  8. equals(array)
    Array.prototype.equals = function (array) {
      if (!array)
        return false;
      if (this.length != array.length)
        return false;
      for (var i = 0, l=this.length; i < l; i++) {
        if (this[i] instanceof Array && array[i] instanceof Array) {
          if (!this[i].equals(array[i]))
            return false;
    ...
    
  9. equals(array)
    Array.prototype.equals = function (array) {
        if (!array)
            return false;
        if (this.length != array.length)
            return false;
        for (var i = 0, l=this.length; i < l; i++) {
            if (this[i] instanceof Array && array[i] instanceof Array) {
                if (!this[i].compare(array[i]))
                    return false;
    ...