From 27a1b4af13c26008bf246ad12883e9747d416c3d Mon Sep 17 00:00:00 2001 From: DmJSCourse Date: Fri, 28 Aug 2020 08:50:32 +0300 Subject: [PATCH 1/2] done --- package.json | 2 +- src/deepEqual.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 29cd1e0..d09183b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "license": "GPL-3.0", "devDependencies": { "@mate-academy/eslint-config": "*", - "@mate-academy/scripts": "^0.3.5", + "@mate-academy/scripts": "^0.6.4", "eslint": "^5.16.0", "eslint-plugin-jest": "^22.4.1", "eslint-plugin-node": "^8.0.1", diff --git a/src/deepEqual.js b/src/deepEqual.js index 860208b..bd7331a 100644 --- a/src/deepEqual.js +++ b/src/deepEqual.js @@ -20,7 +20,25 @@ * @return {boolean} */ function deepEqual(a, b) { - // write code here + if (a === null && b === null) { + return true; + } + + if (a === null || b === null) { + return false; + } + + if (typeof a === 'object' && typeof b === 'object') { + if (Object.keys(a).length === Object.keys(b).length) { + return Object.keys(a).every(key => deepEqual(a[key], b[key])); + } + } + + if (a === b) { + return true; + } + + return false; } module.exports = deepEqual; From 31859b1251b9b835645cba7734056bf868866353 Mon Sep 17 00:00:00 2001 From: DmJSCourse Date: Fri, 28 Aug 2020 13:57:15 +0300 Subject: [PATCH 2/2] fixed code --- src/deepEqual.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/deepEqual.js b/src/deepEqual.js index bd7331a..c704a8b 100644 --- a/src/deepEqual.js +++ b/src/deepEqual.js @@ -20,7 +20,7 @@ * @return {boolean} */ function deepEqual(a, b) { - if (a === null && b === null) { + if (Object.is(a, b)) { return true; } @@ -34,10 +34,6 @@ function deepEqual(a, b) { } } - if (a === b) { - return true; - } - return false; }