From 2d4a7374e9341d9941c75d52ad032c1974691f65 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Mon, 22 Jan 2024 12:23:35 +0200 Subject: [PATCH 1/2] Solution --- src/inverseRobot.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/inverseRobot.js b/src/inverseRobot.js index 4906e020..0a86c7e5 100644 --- a/src/inverseRobot.js +++ b/src/inverseRobot.js @@ -7,7 +7,17 @@ */ function inverseRobot(robot) { - // write code here + const result = {}; + + for (const key in robot) { + if (result[robot[key]]) { + return null; + } + + result[robot[key]] = key; + } + + return result; } module.exports = inverseRobot; From 860ee8caa71bacc8446130184bcc9aacb4c6c630 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Mon, 22 Jan 2024 14:50:06 +0200 Subject: [PATCH 2/2] Solution --- src/inverseRobot.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/inverseRobot.js b/src/inverseRobot.js index 0a86c7e5..d3b20eaf 100644 --- a/src/inverseRobot.js +++ b/src/inverseRobot.js @@ -7,17 +7,19 @@ */ function inverseRobot(robot) { - const result = {}; + const repairedRobot = {}; for (const key in robot) { - if (result[robot[key]]) { + const objectValue = robot[key]; + + if (repairedRobot.hasOwnProperty(objectValue)) { return null; } - result[robot[key]] = key; + repairedRobot[objectValue] = key; } - return result; + return repairedRobot; } module.exports = inverseRobot;