- [VARIABLES] - use variables for the main values so that you'll be able to reuse them and give them descriptive names.
- [CODE STYLE] - use correct check for property presence in object. Some properties can be present, but still contain falsy value.
GOOD EXAMPLE:
if (key in robot) {
EVEN BETTER EXAMPLE:
if (robot.hasOwnProperty(key)) {
BAD EXAMPLE:
if (robot[key] === undefined) {
if (robot[key]) {
-
[NAMING] - use proper names for variables - if you want to name variable
result, pick a better one :) -
[CODE STYLE] - You should return the value immediately in
ifstatements. And don't useelseafter return statement. Ifreturnis performed - code after it won't be executed anyway.
BAD EXAMPLE:
if (condition) {
return x;
} else {
return y;
}
GOOD EXAMPLE:
if (condition) {
return x;
}
return y;