mirror of https://github.com/tc39/test262.git
Use SameValue
This commit is contained in:
parent
59a1a016b7
commit
c674362d1a
|
@ -5,13 +5,20 @@ description: |
|
||||||
Compare the contents of two arrays
|
Compare the contents of two arrays
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
function isSameValue(a, b) {
|
||||||
|
if (a === 0 && b === 0) return 1 / a === 1 / b;
|
||||||
|
if (a !== a && b !== b) return true;
|
||||||
|
|
||||||
|
return a === b;
|
||||||
|
}
|
||||||
|
|
||||||
function compareArray(a, b) {
|
function compareArray(a, b) {
|
||||||
if (b.length !== a.length) {
|
if (b.length !== a.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < a.length; i++) {
|
for (var i = 0; i < a.length; i++) {
|
||||||
if (b[i] !== a[i]) {
|
if (!isSameValue(b[i], a[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
compareArray uses SameValue for value comparison.
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(compareArray([NaN], [NaN]));
|
||||||
|
assert(!compareArray([0], [-0]));
|
Loading…
Reference in New Issue