-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add my ugly solution. i think so, maybe not)) #2703
base: master
Are you sure you want to change the base?
Conversation
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.
Nice work! Added comments to fix
src/transformState.js
Outdated
// write code here | ||
function transformState(state, action) { | ||
for (const obj of action) { | ||
// to iterate all objects in array. |
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.
Consider removing redundant comments
src/transformState.js
Outdated
for (const [key, value] of Object.entries(obj)) { | ||
// to iterate every object and split on keys and values. | ||
// | ||
// conditions check |
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.
Consider removing redundant comments
src/transformState.js
Outdated
} | ||
|
||
if (obj[key] === obj.extraData) { | ||
// add key and value to the object |
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.
Consider removing redundant comments
src/transformState.js
Outdated
} | ||
|
||
if (obj[key] === obj.keysToRemove) { | ||
// delete properies |
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.
Consider removing redundant comments
@@ -4,8 +4,36 @@ | |||
* @param {Object} state | |||
* @param {Object[]} actions | |||
*/ | |||
function transformState(state, actions) { |
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.
You can place here a bunch of helper constants, for example:
const CLEAR = 'clear';
And use it instead of magic strings (a considered programming antipattern) in your code
src/transformState.js
Outdated
|
||
if (obj[key] === obj.extraData) { | ||
// add key and value to the object | ||
for (const [k, v] of Object.entries(obj[key])) { |
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.
Consider using Object.assign instead of looping through every key
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.
Good job!
function transformState(state, action) { | ||
const CLEAR = 'clear'; | ||
|
||
for (const obj of action) { |
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.
Destructure obj
Seems like it works