forked from 9-6-pursuit/lab-reference-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (50 loc) · 2.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Adds a new store to the very end of the list.
* @param {Object[]]} stores - An array of store objects.
* @param {Object} store - An object representing a single store. See the instructions for details on its shape.
* @returns {Object[]} The same `stores` array that was inputted.
*/
function addNewStore(stores, store) {
let addNewStore = stores.push(store)
return stores
}
/**
* Removes a store object at the given position.
* @param {Object[]]} stores - An array of store objects.
* @param {number} index - A number representing the index of the store to be removed from the array.
* @returns {Object[]} The same `stores` array that was inputted.
*/
// function removeStoreAtPosition(stores, index) {
// let removeStoreAtPosition = stores.splice(0,stores)
// return stores
// }
function removeStoreAtPosition(stores, index) {
stores.splice(index,1)
return stores
}
/**
* Creates a duplicate of the `store` object. No references should be shared between the inputted `store` and the result.
* @param {Object} store - An object representing a single store. See the instructions for details on its shape.
* @returns {Object} The duplicated store object. This should not be the same as the store that was inputted.
*/
function duplicateStore(store) {
// let duplicateStore = store
// //return duplicateStore
// let copied1 = JSON.parse(JSON.stringify(store));
// // copied.boardGames = 'Jane'; // disconnected
// // copied.address.street = 'Amphitheatre Parkway';
// // copied.address.city = 'Mountain View';
// // return duplicateStore
// let copied = Object.assign({}, store);
// // copied.boardGames = 'Jane'; // disconnected
// // copiedPerson.address.street = 'Amphitheatre Parkway'; // connected
// // copiedPerson.address.city = 'Mountain View'; // connected
// return duplicateStore
const newObj = JSON.parse(JSON.stringify(store))
return newObj
}
module.exports = {
addNewStore,
removeStoreAtPosition,
duplicateStore,
};