From 6dbec7e44f6945bb910eced22786296163f626ce Mon Sep 17 00:00:00 2001
From: ramyasree <39062317+RamyasreeSiri@users.noreply.github.com>
Date: Sat, 2 Mar 2019 04:23:43 +0530
Subject: [PATCH] Added hints and solutions to Redux exercises (#35244)
* Added hints and solutions to Redux exercises
solution to Redux exercise: Copy an Object with Object.assign
* Added the full code for the solution
---
.../index.md | 35 +++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/guide/english/certifications/front-end-libraries/redux/copy-an-object-with-object.assign/index.md b/guide/english/certifications/front-end-libraries/redux/copy-an-object-with-object.assign/index.md
index 4d8d0c4fed..51d4c96408 100644
--- a/guide/english/certifications/front-end-libraries/redux/copy-an-object-with-object.assign/index.md
+++ b/guide/english/certifications/front-end-libraries/redux/copy-an-object-with-object.assign/index.md
@@ -3,8 +3,39 @@ title: Copy an Object with Object.assign
---
## Copy an Object with Object.assign
-This is a stub. Help our community expand it.
+The goal of this challenge is to enforce state immutability when state is an object.
-This quick style guide will help ensure your pull request gets accepted.
+### Hint 1
+Use the method ```Object.assign({}, obj1, obj2)``` in return. Pass ```state``` as obj1.
+### Hint 2
+The obj2 should be the updated ```{key: value}``` pair of your state.
+
+### Solution
+```
+const defaultState = {
+ user: 'CamperBot',
+ status: 'offline',
+ friends: '732,982',
+ community: 'freeCodeCamp'
+};
+
+const immutableReducer = (state = defaultState, action) => {
+ switch(action.type) {
+ case 'ONLINE':
+ // to enforce state immutability, return a new state object using Object.assign() method
+ return Object.assign({}, state, {status: 'online'});
+ default:
+ return state;
+ }
+};
+
+const wakeUp = () => {
+ return {
+ type: 'ONLINE'
+ }
+};
+
+const store = Redux.createStore(immutableReducer);
+```