compareArray.js 624 B

123456789101112131415161718192021222324
  1. // Copyright (C) 2017 Ecma International. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. description: |
  5. Compare the contents of two arrays
  6. ---*/
  7. function compareArray(a, b) {
  8. if (b.length !== a.length) {
  9. return false;
  10. }
  11. for (var i = 0; i < a.length; i++) {
  12. if (b[i] !== a[i]) {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }
  18. assert.compareArray = function(actual, expected, message) {
  19. assert(compareArray(actual, expected),
  20. 'Expected [' + actual.join(', ') + '] and [' + expected.join(', ') + '] to have the same contents. ' + message);
  21. };