Proof of Work · Challenge
Decide if two values are the same thing, all the way down.
about 25 min · 7 required tests · in the browser
What is recorded: when you save, your Result page shows your code, which tests passed, how many times you ran the tests, how many versions you tried, the time from first run to save, and the largest jump in code between runs. Anyone with the link can see it. The suggested time is not enforced.
Memoization, change detection, and assertion libraries all need to answer one question: are these two values the same, even if they are not the same object? === only says yes for the same reference.
Implement deepEqual(a, b). It returns true when the two values have the same structure and contents.
It must handle:
1 and "1" are different. null and undefined are different.NaN, which equals NaN here even though NaN === NaN is false.Date objects, equal when they hold the same time.Two values with different sets of keys are never equal, in either direction.
deepEqual({ a: [1, { b: 2 }] }, { a: [1, { b: 2 }] }) // true
deepEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // true
deepEqual({ a: 1 }, { a: 1, b: undefined }) // false
deepEqual(new Date(0), new Date(1)) // falseMaps, Sets, and class instances are out of scope.
Write a top-level function named deepEqual. Do not use export or module.exports.
Press Esc, then Tab, to leave the editor.
⌘ / Ctrl + Enter runs the tests
Hiring developers? See how teams use this.
Graded on
0/7
Other builds