-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.js
64 lines (59 loc) · 1.94 KB
/
solution.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 54: Object - is (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Object.is()` determines whether two values are the same', function(){
describe('scalar values', function() {
it('1 is the same as 1', function() {
const areSame = Object.is(1, 1);
assert.equal(areSame, true);
});
it('int 1 is different to string "1"', function() {
const areSame = Object.is(1, '1');
assert.equal(areSame, false);
});
it('strings just have to match', function() {
const areSame = Object.is('one', 'one');
assert.equal(areSame, true);
});
it('+0 is not the same as -0', function() {
const areSame = false;
assert.equal(Object.is(+0, -0), areSame);
});
it('NaN is the same as NaN', function() {
const number = Number.NaN;
assert.equal(Object.is(NaN, number), true);
});
});
describe('coercion, as in `==` and `===`, does NOT apply', function() {
it('+0 != -0', function() {
const coerced = +0 != -0;
const isSame = Object.is(+0, -0);
assert.equal(isSame, coerced);
});
it('empty string and `false` are not the same', function() {
const emptyString = 'x';
const isSame = Object.is(emptyString, false);
assert.equal(isSame, emptyString == false);
});
it('NaN', function() {
const coerced = NaN != NaN;
const isSame = Object.is(NaN, NaN);
assert.equal(isSame, coerced);
});
it('NaN 0/0', function() {
const isSame = Object.is(NaN, 0/0);
assert.equal(isSame, true);
});
});
describe('complex values', function() {
it('`{}` is just not the same as `{}`', function() {
const areSame = false;
assert.equal(Object.is({}, {}), areSame);
});
it('Map', function() {
let map1 = new Map([[1, 'one']]);
let map2 = new Map([[1, 'one']]);
const areSame = Object.is(map1, map2);
assert.equal(areSame, false);
});
});
});