All files / mongoose/lib/helpers/indexes isIndexSpecEqual.js

9.09% Statements 1/11
0% Branches 0/6
0% Functions 0/1
10% Lines 1/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                              1x                                  
'use strict';
 
/**
 * Compares two index specifications to determine if they are equal.
 *
 * #### Example:
 *     isIndexSpecEqual({ a: 1, b: 1 }, { a: 1, b: 1 }); // true
 *     isIndexSpecEqual({ a: 1, b: 1 }, { b: 1, a: 1 }); // false
 *     isIndexSpecEqual({ a: 1, b: -1 }, { a: 1, b: 1 }); // false
 *
 * @param {Object} spec1 The first index specification to compare.
 * @param {Object} spec2 The second index specification to compare.
 * @returns {Boolean} Returns true if the index specifications are equal, otherwise returns false.
 */
 
module.exports = function isIndexSpecEqual(spec1, spec2) {
  const spec1Keys = Object.keys(spec1);
  const spec2Keys = Object.keys(spec2);
 
  if (spec1Keys.length !== spec2Keys.length) {
    return false;
  }
 
  for (let i = 0; i < spec1Keys.length; i++) {
    const key = spec1Keys[i];
    if (key !== spec2Keys[i] || spec1[key] !== spec2[key]) {
      return false;
    }
  }
 
  return true;
};