forked from 9-6-pursuit/lab-reference-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (45 loc) · 1.54 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
/**
* 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) {
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) {
// console.log(stores[0]);
// console.log(stores[1]);
// console.log(stores[2]);
// console.log(typeof index)
// console.log(typeof stores)
// console.log(index.length)
stores.splice(index, 1)
return stores
// 1 1 0 2
}
/**
* 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) {
return JSON.parse(JSON.stringify(store));
}
module.exports = {
addNewStore,
removeStoreAtPosition,
duplicateStore,
};