diff --git a/index.js b/index.js index 784b4d4..69e728c 100644 --- a/index.js +++ b/index.js @@ -4,22 +4,94 @@ * @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) {} + + +/* +WRONG ANSWER WAS { + stores.unshift[store] + return(stores)} +*/ + +function addNewStore(stores, store) { + stores.push(store); //push adds the input in the paranthesis to the end of the stores array + 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) {} + +/carina + +*/ +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) {} +function duplicateStore(store) { + let storeCopy = {}; //objectCopy will store a copy of the store + let key; + for (key in store) { //'in' is an inbuilt operator in JS which is used to check if a particular property exists in an object or not + storeCopy[key] = store[key]; //copies each property to the objectCopy object +} +store.boardGames = ["Monopoly","Parcheesi","Funtimes"] +store.address = { + street: "8675 309th Street", + city: "Lulav", + state: "HI", + zip: "09898", +} + return storeCopy; +} + + +/** + const store = { + name: "Gamestoria", + boardGames: [ + "Terra Mystica", + "Alhambra", + "Scythe", + "Carcassonne", + "Azul", + ], + address: { + street: "42-11 Broadway", + city: "Astoria", + state: "NY", + zip: "11103", + }, + }; + +let copyStore = {}; + let keys = Object.keys(store); + for (let i = 0; len = keys.length; i < len, i++) { + copyStore[keys] = store[keys]; + } + return copyStore + */ + +// const sheeps = ['🐑', '🐑']; +// const sheeps2 = sheeps; +// sheeps2.push('🐺'); +// console.log(sheeps2); +// // [ '🐑', '🐑', '🐺' ] + +// // Ahhh 😱 , our original sheeps have changed?! +// console.log(sheeps); +// // [ '🐑', '🐑', '🐺' ] module.exports = { addNewStore, diff --git a/package-lock.json b/package-lock.json index e89f007..5baa863 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "8-0-reference-types-lab", "version": "1.0.0", "license": "ISC", "devDependencies": { @@ -1073,9 +1074,9 @@ } }, "node_modules/ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, "engines": { "node": ">=8" @@ -1307,14 +1308,20 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001242", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001242.tgz", - "integrity": "sha512-KvNuZ/duufelMB3w2xtf9gEWCSxJwUgoxOx5b6ScLXC4kPc9xsczUVCPrQU26j5kOsHM4pSUL54tAZt5THQKug==", - "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "version": "1.0.30001420", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001420.tgz", + "integrity": "sha512-OnyeJ9ascFA9roEj72ok2Ikp7PHJTKubtEJIQ/VK3fdsS50q4KWy+Z5X0A1/GswEItKX0ctAp8n4SYDE7wTu6A==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + } + ] }, "node_modules/chalk": { "version": "4.1.1", @@ -3033,10 +3040,13 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", + "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/ms": { "version": "2.1.2", @@ -3627,9 +3637,9 @@ "dev": true }, "node_modules/tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "node_modules/to-fast-properties": { @@ -4797,9 +4807,9 @@ } }, "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true }, "ansi-styles": { @@ -4979,9 +4989,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001242", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001242.tgz", - "integrity": "sha512-KvNuZ/duufelMB3w2xtf9gEWCSxJwUgoxOx5b6ScLXC4kPc9xsczUVCPrQU26j5kOsHM4pSUL54tAZt5THQKug==", + "version": "1.0.30001420", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001420.tgz", + "integrity": "sha512-OnyeJ9ascFA9roEj72ok2Ikp7PHJTKubtEJIQ/VK3fdsS50q4KWy+Z5X0A1/GswEItKX0ctAp8n4SYDE7wTu6A==", "dev": true }, "chalk": { @@ -6298,9 +6308,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", + "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", "dev": true }, "ms": { @@ -6750,9 +6760,9 @@ "dev": true }, "tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "to-fast-properties": {