-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Solution #2678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Solution #2678
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,17 @@ | |
| */ | ||
|
|
||
| function inverseRobot(robot) { | ||
| // write code here | ||
| const truePosition = {}; | ||
|
|
||
| for (const key in robot) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
| } | ||
|
|
||
| module.exports = inverseRobot; | ||
There was a problem hiding this comment.
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.