Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [14.x]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^0.3.5",
"@mate-academy/scripts": "^1.8.1",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
Expand Down
12 changes: 11 additions & 1 deletion src/inverseRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
*/

function inverseRobot(robot) {
// write code here
const truePosition = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 'truePosition' is not very descriptive of its purpose. Consider renaming it to something more indicative of its role, such as 'invertedRobot' or 'swappedPairs', to improve code readability.


for (const key in robot) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good practice to check if the property belongs to the object itself and not to its prototype chain. Use 'robot.hasOwnProperty(key)' to ensure that the key is a direct property of 'robot'.

if (truePosition.hasOwnProperty(robot[key])) {
return null;
}

truePosition[robot[key]] = key;
}

return truePosition;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function correctly returns the 'truePosition' object if no duplicate values are found in the input 'robot' object, adhering to the task requirements.

}

module.exports = inverseRobot;