Skip to content

Solution#2678

Open
unholysearcher wants to merge 2 commits intomate-academy:masterfrom
unholysearcher:develop
Open

Solution#2678
unholysearcher wants to merge 2 commits intomate-academy:masterfrom
unholysearcher:develop

Conversation

@unholysearcher
Copy link

No description provided.


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.

// write code here
const truePosition = {};

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'.

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.

Copy link

@lerastarynets lerastarynets left a comment

Choose a reason for hiding this comment

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

You're on the right track!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants