├── assets ├── npm_start.png ├── split_terminal.png └── tests_debug_terminal_final.png ├── .eslintrc.json ├── babel.config.js ├── package.json ├── README.md ├── .gitignore ├── codegrade_mvp1.test.js ├── jest.config.js └── index.js /assets/npm_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/web-module-challenge-arrays/HEAD/assets/npm_start.png -------------------------------------------------------------------------------- /assets/split_terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/web-module-challenge-arrays/HEAD/assets/split_terminal.png -------------------------------------------------------------------------------- /assets/tests_debug_terminal_final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/web-module-challenge-arrays/HEAD/assets/tests_debug_terminal_final.png -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true, 5 | "node": true, 6 | "jest": true 7 | }, 8 | "extends": [ 9 | "eslint:recommended" 10 | ], 11 | "parserOptions": { 12 | "ecmaVersion": 12, 13 | "sourceType": "module" 14 | }, 15 | "rules": {} 16 | } 17 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | test: { 4 | plugins: [ 5 | '@babel/plugin-transform-runtime', 6 | ], 7 | presets: [ 8 | [ 9 | '@babel/preset-env', 10 | { 11 | modules: 'commonjs', 12 | debug: false 13 | } 14 | ] 15 | ] 16 | } 17 | } 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codegraded-project-js", 3 | "version": "0.0.9", 4 | "main": "index.js", 5 | "scripts": { 6 | "start": "nodemon index.js", 7 | "test": "jest --watchAll --verbose --forceExit --silent" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/BloomInstituteOfTechnology/codegraded-project-js.git" 12 | }, 13 | "devDependencies": { 14 | "@babel/core": "7.17.5", 15 | "@babel/plugin-transform-runtime": "7.17.0", 16 | "@babel/preset-env": "7.16.11", 17 | "@types/jest": "27.4.1", 18 | "eslint": "8.10.0", 19 | "jest": "27.5.1", 20 | "nodemon": "2.0.15" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Advanced CSS and Intro to JavaScript 2 | 3 | ## Arrays 4 | 5 | ## Objectives 6 | 7 | - use arrays to store and access data 8 | - use array properties and array methods 9 | 10 | ## Introduction 11 | 12 | Baskin Robins, a global chain of ice cream parlors, first opened in 1945 and served 31 flavors of Ice Cream. They have grown to almost 6,000 franchises world wide and have now became famous for serving exactly 31 flavors at a time. Since they first opened, they no longer serve the same 31 flavors, but they do always have exactly 31 ice cream flavors available. 13 | 14 | Your challenge today will be to work with their array of ice cream flavors to access, remove, and add flavors, all while ensuring the length never exceeds 31. 15 | 16 | ## Instructions 17 | 18 | ### Task 1: Set up Project 19 | 20 | Using VSCode and Command Line: 21 | 22 | 23 | 1. Fork the repo 24 | 2. Go into canvas and connect your repo to codegrade 25 | 3. Clone your forked version of the repo 26 | 4. DO NOT CREATE A BRANCH. You will be pushing your changes to the main/master today 27 | 5. cd into your repo 28 | 6. open the terminal in your vs code and type `npm install` 29 | 7. next type `npm run test` in your terminal 30 | 8. Complete your work making regular commits to main/master. Your codegrade score will update each time you make a push. 31 | 32 | ### Task 2: MVP 33 | 34 | Find the file `index.js` and complete the tasks until your returns look like the expected returns. Do not use any of the forbidden methods! Forbidden methods are `.forEach()`, `.map()`, `.filter()` and `.reduce()` 35 | 36 | ### Testing & Debugging 37 | 38 | Open a second terminal inside of your project by clicking on the split terminal icon 39 | ![alt text](assets/split_terminal.png "Split Terminal") 40 | 41 | Inside of your second terminal type `npm start` 42 | ![alt text](assets/npm_start.png "type npm start") 43 | 44 | You will be running your tests in one terminal and debugging in the other. As you work on your code you should make use of `console.log` to check your progress and debug. 45 | ![alt text](assets/tests_debug_terminal_final.png "your terminal should look like this") 46 | 47 | 48 | ### Task 3: Stretch 49 | 50 | There are several stretch goals inside `index.js`. You may work on these once you have finished MVP requirements for the day! 51 | 52 | ## FAQs 53 | 54 | **Why aren't my results showing up in the console?** 55 | 56 | Make sure you are invoking your function after defining and wrapping a console.log around the invocation in order to view results in the console. 57 | 58 | EXAMPLE: console.log(myFunction(argument)) 59 | 60 | ## Resources 61 | 62 | 🤝[W3 Schools - JavaScript Arrays](https://www.w3schools.com/js/js_arrays.asp) 63 | 64 | 🍦[Baskin Robins Flavors](https://simple.wikipedia.org/wiki/Baskin-Robbins) 65 | 66 | ## Submission format 67 | 68 | Please submit your project via codegrade by following [these instructions](https://bloomtech.notion.site/bloomtech/BloomTech-Git-Flow-Step-by-step-269f68ae3bf64eb689a8328715a179f9) See part 2, submitting an assignment with codegrade 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # Snowpack dependency directory (https://snowpack.dev/) 45 | web_modules/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | .parcel-cache 78 | 79 | # Next.js build output 80 | .next 81 | out 82 | 83 | # Nuxt.js build / generate output 84 | .nuxt 85 | dist 86 | 87 | # Gatsby files 88 | .cache/ 89 | # Comment in the public line in if your project uses Gatsby and not Next.js 90 | # https://nextjs.org/blog/next-9-1#public-directory-support 91 | # public 92 | 93 | # vuepress build output 94 | .vuepress/dist 95 | 96 | # Serverless directories 97 | .serverless/ 98 | 99 | # FuseBox cache 100 | .fusebox/ 101 | 102 | # DynamoDB Local files 103 | .dynamodb/ 104 | 105 | # TernJS port file 106 | .tern-port 107 | 108 | # Stores VSCode versions used for testing VSCode extensions 109 | .vscode-test 110 | 111 | # yarn v2 112 | .yarn/cache 113 | .yarn/unplugged 114 | .yarn/build-state.yml 115 | .yarn/install-state.gz 116 | .pnp.* 117 | # Logs 118 | logs 119 | *.log 120 | npm-debug.log* 121 | yarn-debug.log* 122 | yarn-error.log* 123 | lerna-debug.log* 124 | .pnpm-debug.log* 125 | 126 | # Diagnostic reports (https://nodejs.org/api/report.html) 127 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 128 | 129 | # Runtime data 130 | pids 131 | *.pid 132 | *.seed 133 | *.pid.lock 134 | 135 | # Directory for instrumented libs generated by jscoverage/JSCover 136 | lib-cov 137 | 138 | # Coverage directory used by tools like istanbul 139 | coverage 140 | *.lcov 141 | 142 | # nyc test coverage 143 | .nyc_output 144 | 145 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 146 | .grunt 147 | 148 | # Bower dependency directory (https://bower.io/) 149 | bower_components 150 | 151 | # node-waf configuration 152 | .lock-wscript 153 | 154 | # Compiled binary addons (https://nodejs.org/api/addons.html) 155 | build/Release 156 | 157 | # Dependency directories 158 | node_modules/ 159 | jspm_packages/ 160 | 161 | # Snowpack dependency directory (https://snowpack.dev/) 162 | web_modules/ 163 | 164 | # TypeScript cache 165 | *.tsbuildinfo 166 | 167 | # Optional npm cache directory 168 | .npm 169 | 170 | # Optional eslint cache 171 | .eslintcache 172 | 173 | # Microbundle cache 174 | .rpt2_cache/ 175 | .rts2_cache_cjs/ 176 | .rts2_cache_es/ 177 | .rts2_cache_umd/ 178 | 179 | # Optional REPL history 180 | .node_repl_history 181 | 182 | # Output of 'npm pack' 183 | *.tgz 184 | 185 | # Yarn Integrity file 186 | .yarn-integrity 187 | 188 | # dotenv environment variables file 189 | .env 190 | .env.test 191 | .env.production 192 | 193 | # parcel-bundler cache (https://parceljs.org/) 194 | .cache 195 | .parcel-cache 196 | 197 | # Next.js build output 198 | .next 199 | out 200 | 201 | # Nuxt.js build / generate output 202 | .nuxt 203 | dist 204 | 205 | # Gatsby files 206 | .cache/ 207 | # Comment in the public line in if your project uses Gatsby and not Next.js 208 | # https://nextjs.org/blog/next-9-1#public-directory-support 209 | # public 210 | 211 | # vuepress build output 212 | .vuepress/dist 213 | 214 | # Serverless directories 215 | .serverless/ 216 | 217 | # FuseBox cache 218 | .fusebox/ 219 | 220 | # DynamoDB Local files 221 | .dynamodb/ 222 | 223 | # TernJS port file 224 | .tern-port 225 | 226 | # Stores VSCode versions used for testing VSCode extensions 227 | .vscode-test 228 | 229 | # yarn v2 230 | .yarn/cache 231 | .yarn/unplugged 232 | .yarn/build-state.yml 233 | .yarn/install-state.gz 234 | .pnp.* 235 | 236 | # Mac cruft 237 | .DS_Store 238 | 239 | # VSCode 240 | .vscode 241 | -------------------------------------------------------------------------------- /codegrade_mvp1.test.js: -------------------------------------------------------------------------------- 1 | import functions from './index'; 2 | // import{originalFlavors}from '../index'; 3 | let originalFlavors; 4 | beforeEach(()=>{ 5 | originalFlavors = ["Banana Nut Fudge", 6 | "Black Walnut", 7 | "Burgundy Cherry", 8 | "Butterscotch Ribbon", 9 | "Cherry Macaron", 10 | "Chocolate", 11 | "Chocolate Almond", 12 | "Chocolate Chip", 13 | "Chocolate Fudge", 14 | "Chocolate Mint", 15 | "Chocolate Ribbon", 16 | "Coffee", 17 | "Coffee Candy", 18 | "Date Nut", 19 | "Eggnog", 20 | "French Vanilla", 21 | "Green Mint Stick", 22 | "Lemon Crisp", 23 | "Lemon Custard", 24 | "Lemon Sherbet", 25 | "Maple Nut", 26 | "Orange Sherbet", 27 | "Peach", 28 | "Peppermint Fudge Ribbon", 29 | "Peppermint Stick", 30 | "Pineapple Sherbet", 31 | "Raspberry Sherbet", 32 | "Rocky Road", 33 | "Strawberry", 34 | "Vanilla", 35 | "Vanilla Burnt Almond"]; 36 | }) 37 | 38 | describe('fooFunction', ()=>{ 39 | it('foo returns foo', ()=>{ 40 | expect(functions.foo()).toBe('bar'); 41 | }) 42 | }); 43 | describe('copy', ()=>{ 44 | it('copy returns array', ()=>{ 45 | expect(functions.copy(originalFlavors)).toEqual(originalFlavors); 46 | }) 47 | }); 48 | describe('is31Flavors', ()=>{ 49 | it('is31Flavours returns true', ()=>{ 50 | expect(functions.is31Flavors(originalFlavors)).toBe(true); 51 | }) 52 | }); 53 | describe('addFlavor', ()=>{ 54 | it('addFlavor returns array with new flavor at beginning', ()=>{ 55 | expect(functions.addFlavor(originalFlavors, 'Rainbow Sherbert')).toEqual([ 56 | 'Rainbow Sherbert', 57 | 'Banana Nut Fudge', 58 | 'Black Walnut', 59 | 'Burgundy Cherry', 60 | 'Butterscotch Ribbon', 61 | 'Cherry Macaron', 62 | 'Chocolate', 63 | 'Chocolate Almond', 64 | 'Chocolate Chip', 65 | 'Chocolate Fudge', 66 | 'Chocolate Mint', 67 | 'Chocolate Ribbon', 68 | 'Coffee', 69 | 'Coffee Candy', 70 | 'Date Nut', 71 | 'Eggnog', 72 | 'French Vanilla', 73 | 'Green Mint Stick', 74 | 'Lemon Crisp', 75 | 'Lemon Custard', 76 | 'Lemon Sherbet', 77 | 'Maple Nut', 78 | 'Orange Sherbet', 79 | 'Peach', 80 | 'Peppermint Fudge Ribbon', 81 | 'Peppermint Stick', 82 | 'Pineapple Sherbet', 83 | 'Raspberry Sherbet', 84 | 'Rocky Road', 85 | 'Strawberry', 86 | 'Vanilla', 87 | 'Vanilla Burnt Almond' 88 | ]); 89 | }) 90 | }); 91 | describe('removeLastFlavor', ()=>{ 92 | it('removeLastFlavor returns array with last flavor removed', ()=>{ 93 | expect(functions.removeLastFlavor(originalFlavors)).toEqual([ 94 | 'Banana Nut Fudge', 95 | 'Black Walnut', 96 | 'Burgundy Cherry', 97 | 'Butterscotch Ribbon', 98 | 'Cherry Macaron', 99 | 'Chocolate', 100 | 'Chocolate Almond', 101 | 'Chocolate Chip', 102 | 'Chocolate Fudge', 103 | 'Chocolate Mint', 104 | 'Chocolate Ribbon', 105 | 'Coffee', 106 | 'Coffee Candy', 107 | 'Date Nut', 108 | 'Eggnog', 109 | 'French Vanilla', 110 | 'Green Mint Stick', 111 | 'Lemon Crisp', 112 | 'Lemon Custard', 113 | 'Lemon Sherbet', 114 | 'Maple Nut', 115 | 'Orange Sherbet', 116 | 'Peach', 117 | 'Peppermint Fudge Ribbon', 118 | 'Peppermint Stick', 119 | 'Pineapple Sherbet', 120 | 'Raspberry Sherbet', 121 | 'Rocky Road', 122 | 'Strawberry', 123 | 'Vanilla', 124 | ]); 125 | }) 126 | }); 127 | describe('getFlavorByIndex', ()=>{ 128 | it('getFlavorByIndex returns string at index', ()=>{ 129 | expect(functions.getFlavorByIndex(originalFlavors, 2)).toBe("Burgundy Cherry"); 130 | }) 131 | }); 132 | 133 | describe('removeFlavorByName', ()=>{ 134 | it('removeFlavorByName returns array with specified removed', ()=>{ 135 | expect(functions.removeFlavorByName(originalFlavors, 'Vanilla')).toEqual([ 136 | 'Banana Nut Fudge', 137 | 'Black Walnut', 138 | 'Burgundy Cherry', 139 | 'Butterscotch Ribbon', 140 | 'Cherry Macaron', 141 | 'Chocolate', 142 | 'Chocolate Almond', 143 | 'Chocolate Chip', 144 | 'Chocolate Fudge', 145 | 'Chocolate Mint', 146 | 'Chocolate Ribbon', 147 | 'Coffee', 148 | 'Coffee Candy', 149 | 'Date Nut', 150 | 'Eggnog', 151 | 'French Vanilla', 152 | 'Green Mint Stick', 153 | 'Lemon Crisp', 154 | 'Lemon Custard', 155 | 'Lemon Sherbet', 156 | 'Maple Nut', 157 | 'Orange Sherbet', 158 | 'Peach', 159 | 'Peppermint Fudge Ribbon', 160 | 'Peppermint Stick', 161 | 'Pineapple Sherbet', 162 | 'Raspberry Sherbet', 163 | 'Rocky Road', 164 | 'Strawberry', 165 | "Vanilla Burnt Almond" 166 | ]); 167 | }) 168 | }); 169 | 170 | describe('filterByWord', ()=>{ 171 | it('filterByWord returns a new array items containing word', ()=>{ 172 | expect(functions.filterByWord(originalFlavors, 'Chocolate')).toEqual([ 173 | 'Chocolate', 174 | 'Chocolate Almond', 175 | 'Chocolate Chip', 176 | 'Chocolate Fudge', 177 | 'Chocolate Mint', 178 | 'Chocolate Ribbon' 179 | ]); 180 | }) 181 | }); 182 | 183 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * For a detailed explanation regarding each configuration property, visit: 3 | * https://jestjs.io/docs/en/configuration.html 4 | */ 5 | 6 | module.exports = { 7 | // All imported modules in your tests should be mocked automatically 8 | // automock: false, 9 | 10 | // Stop running tests after `n` failures 11 | // bail: 0, 12 | 13 | // The directory where Jest should store its cached dependency information 14 | // cacheDirectory: "/private/var/folders/78/wsw4bc497l1b0dlb3f77xh380000gn/T/jest_dx", 15 | 16 | // Automatically clear mock calls and instances between every test 17 | // clearMocks: false, 18 | 19 | // Indicates whether the coverage information should be collected while executing the test 20 | // collectCoverage: false, 21 | 22 | // An array of glob patterns indicating a set of files for which coverage information should be collected 23 | // collectCoverageFrom: undefined, 24 | 25 | // The directory where Jest should output its coverage files 26 | // coverageDirectory: undefined, 27 | 28 | // An array of regexp pattern strings used to skip coverage collection 29 | // coveragePathIgnorePatterns: [ 30 | // "/node_modules/" 31 | // ], 32 | 33 | // Indicates which provider should be used to instrument code for coverage 34 | coverageProvider: "v8", 35 | 36 | // A list of reporter names that Jest uses when writing coverage reports 37 | // coverageReporters: [ 38 | // "json", 39 | // "text", 40 | // "lcov", 41 | // "clover" 42 | // ], 43 | 44 | // An object that configures minimum threshold enforcement for coverage results 45 | // coverageThreshold: undefined, 46 | 47 | // A path to a custom dependency extractor 48 | // dependencyExtractor: undefined, 49 | 50 | // Make calling deprecated APIs throw helpful error messages 51 | // errorOnDeprecated: false, 52 | 53 | // Force coverage collection from ignored files using an array of glob patterns 54 | // forceCoverageMatch: [], 55 | 56 | // A path to a module which exports an async function that is triggered once before all test suites 57 | // globalSetup: undefined, 58 | 59 | // A path to a module which exports an async function that is triggered once after all test suites 60 | // globalTeardown: undefined, 61 | 62 | // A set of global variables that need to be available in all test environments 63 | // globals: {}, 64 | 65 | // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. 66 | // maxWorkers: "50%", 67 | 68 | // An array of directory names to be searched recursively up from the requiring module's location 69 | // moduleDirectories: [ 70 | // "node_modules" 71 | // ], 72 | 73 | // An array of file extensions your modules use 74 | // moduleFileExtensions: [ 75 | // "js", 76 | // "json", 77 | // "jsx", 78 | // "ts", 79 | // "tsx", 80 | // "node" 81 | // ], 82 | 83 | // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module 84 | // moduleNameMapper: {}, 85 | 86 | // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader 87 | // modulePathIgnorePatterns: [], 88 | 89 | // Activates notifications for test results 90 | // notify: false, 91 | 92 | // An enum that specifies notification mode. Requires { notify: true } 93 | // notifyMode: "failure-change", 94 | 95 | // A preset that is used as a base for Jest's configuration 96 | // preset: undefined, 97 | 98 | // Run tests from one or more projects 99 | // projects: undefined, 100 | 101 | // Use this configuration option to add custom reporters to Jest 102 | // reporters: undefined, 103 | 104 | // Automatically reset mock state between every test 105 | // resetMocks: false, 106 | 107 | // Reset the module registry before running each individual test 108 | // resetModules: false, 109 | 110 | // A path to a custom resolver 111 | // resolver: undefined, 112 | 113 | // Automatically restore mock state between every test 114 | // restoreMocks: false, 115 | 116 | // The root directory that Jest should scan for tests and modules within 117 | // rootDir: undefined, 118 | 119 | // A list of paths to directories that Jest should use to search for files in 120 | // roots: [ 121 | // "" 122 | // ], 123 | 124 | // Allows you to use a custom runner instead of Jest's default test runner 125 | // runner: "jest-runner", 126 | 127 | // The paths to modules that run some code to configure or set up the testing environment before each test 128 | // setupFiles: [], 129 | 130 | // A list of paths to modules that run some code to configure or set up the testing framework before each test 131 | // setupFilesAfterEnv: [], 132 | 133 | // The number of seconds after which a test is considered as slow and reported as such in the results. 134 | // slowTestThreshold: 5, 135 | 136 | // A list of paths to snapshot serializer modules Jest should use for snapshot testing 137 | // snapshotSerializers: [], 138 | 139 | // The test environment that will be used for testing 140 | testEnvironment: "node", 141 | 142 | // Options that will be passed to the testEnvironment 143 | // testEnvironmentOptions: {}, 144 | 145 | // Adds a location field to test results 146 | // testLocationInResults: false, 147 | 148 | // The glob patterns Jest uses to detect test files 149 | // testMatch: [ 150 | // "**/__tests__/**/*.[jt]s?(x)", 151 | // "**/?(*.)+(spec|test).[tj]s?(x)" 152 | // ], 153 | 154 | // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped 155 | // testPathIgnorePatterns: [ 156 | // "/node_modules/" 157 | // ], 158 | 159 | // The regexp pattern or array of patterns that Jest uses to detect test files 160 | // testRegex: [], 161 | 162 | // This option allows the use of a custom results processor 163 | // testResultsProcessor: undefined, 164 | 165 | // This option allows use of a custom test runner 166 | // testRunner: "jasmine2", 167 | 168 | // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href 169 | // testURL: "http://localhost", 170 | 171 | // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" 172 | // timers: "real", 173 | 174 | // A map from regular expressions to paths to transformers 175 | // transform: undefined, 176 | 177 | // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation 178 | // transformIgnorePatterns: [ 179 | // "/node_modules/", 180 | // "\\.pnp\\.[^\\/]+$" 181 | // ], 182 | 183 | // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them 184 | // unmockedModulePathPatterns: undefined, 185 | 186 | // Indicates whether each individual test should be reported during the run 187 | // verbose: undefined, 188 | 189 | // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode 190 | // watchPathIgnorePatterns: [], 191 | 192 | // Whether to use watchman for file crawling 193 | // watchman: true, 194 | }; 195 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* ❗❗ REMEMBER TO RETURN ALL OF THE ANSWERS ON THESE TASKS, IF YOU DON'T, THE AUTOGRADER WILL NOT WORK ❗❗*/ 2 | 3 | /* 👀 This is your data ⬇ */ 4 | const originalFlavors = [ 5 | "Banana Nut Fudge", 6 | "Black Walnut", 7 | "Burgundy Cherry", 8 | "Butterscotch Ribbon", 9 | "Cherry Macaron", 10 | "Chocolate", 11 | "Chocolate Almond", 12 | "Chocolate Chip", 13 | "Chocolate Fudge", 14 | "Chocolate Mint", 15 | "Chocolate Ribbon", 16 | "Coffee", 17 | "Coffee Candy", 18 | "Date Nut", 19 | "Eggnog", 20 | "French Vanilla", 21 | "Green Mint Stick", 22 | "Lemon Crisp", 23 | "Lemon Custard", 24 | "Lemon Sherbet", 25 | "Maple Nut", 26 | "Orange Sherbet", 27 | "Peach", 28 | "Peppermint Fudge Ribbon", 29 | "Peppermint Stick", 30 | "Pineapple Sherbet", 31 | "Raspberry Sherbet", 32 | "Rocky Road", 33 | "Strawberry", 34 | "Vanilla", 35 | "Vanilla Burnt Almond" 36 | ] 37 | 38 | /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 1: Copy the Array! 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 39 | We have an array called originalFlavors with 31 flavors (see above). In these tasks, we will be reading and writing data to this array. 40 | With all of these changes going on, we don't want to lose track of the actual, original 31 flavors. So we need to copy the original array! 41 | 42 | /* 43 | Use the copy function below to do the following: 44 | 1. receive an array as a parameter - you will pass in originalFlavors as an argument when the function is invoked. 45 | 2. Return a copy of the received array 46 | */ 47 | 48 | 49 | function copy(/*your code here*/){ 50 | /*your code here*/ 51 | } 52 | 53 | 54 | 55 | /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 56 | Confirm that an array is exactly 31 flavors. Your function should accept: 57 | 1. an array as a parameter 58 | 2. Check to see if the array given is 31 flavors 59 | 3. Your function should return a boolean TRUE if the length of the array is 31 and FALSE if the length of the array is NOT 31. 60 | 61 | 62 | For Example: is31Flavors(originalFlavors) will return true if your code is working properly 63 | */ 64 | 65 | 66 | function is31Flavors(/*your code here*/){ 67 | /*your code here*/ 68 | } 69 | 70 | 71 | 72 | /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 73 | Corporate has come to you with an idea for a new flavor: Rainbow Sherbert! They think this will be a game changer. You need to modify the array to include this flavor. 74 | 75 | Use the addFlavor function below to do the following: 76 | 1. Receive an array in the first parameter that will take the flavors array as an argument 77 | 2. Receive a string in the second parameter that will take the new flavor as as an argument 78 | 3. The function adds the passed flavor to the front of the passed array 79 | 4. The function should return the resulting array 80 | 81 | For example: addFlavor(originalFlavors, "Rainbow Sherbert") should return the array ["Rainbow Sherbert", "Banana Nut Fudge",..."Vanilla Burnt Almond"] 82 | */ 83 | 84 | 85 | function addFlavor(/*your code here*/){ 86 | /*your code here*/ 87 | } 88 | 89 | 90 | 91 | /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 92 | Houston, we have a problem! There are now 32 flavors in the originalFlavors array! Your task is to remove an item from the end of the array. 93 | 94 | Use the removeLastFlavor function below to do the following: 95 | 1. Receive an array 96 | 2. Remove the last item from the received array 97 | 3. Return the resulting array 98 | 99 | For example: running removeLastFlavor(originalFlavors) would return ["Rainbow Sherbert", "Banana Nut Fudge",..."Vanilla"] 100 | */ 101 | 102 | 103 | function removeLastFlavor(/*your code here*/){ 104 | /*your code here*/ 105 | } 106 | 107 | 108 | 109 | /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 110 | Write a function that returns a flavor at a given index in the array. 111 | 112 | Use the getFlavorByIndex function below to do the following: 113 | 1. Recieve an array in the first parameter that will take the flavors array as an argument 114 | 2. Receive a number in the second parameter that will take the the desired index as an argument 115 | 3. Return the flavor located at the received index position 116 | 117 | For example: running getFlavorByIndex(originalFlavors, 2) would return "Black Walnut", assuming Rainbow Sherbert has been added successfully 118 | */ 119 | 120 | 121 | function getFlavorByIndex(/*your code here*/){ 122 | /*your code here*/ 123 | } 124 | 125 | 126 | 127 | /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 128 | As corporate wants to add more and more flavors to their lineup, they've realized that they need to remove flavors based on flavor name, as opposed to just arbitrarily removing the first or last flavor. Your task is to get an index by flavor name, and remove that single flavor from the array. 129 | 130 | Use the removeFlavorByName function below to do the following: 131 | 1. Receive an array in the first parameter that will take the flavors array as an argument 132 | 2. Receive a string in the second parameter that will take the flavor name as as an argument 133 | 3. Remove the received flavor from the received array 134 | 4. Return the resulting array that now contains one less flavor 135 | 136 | For example: running removeFlavorByName(originalFlavors, "Rocky Road") would return an array with the a length of 30 because Rocky Road would have been removed. 137 | 138 | HINT: You can use .splice() for this 139 | */ 140 | 141 | function removeFlavorByName(/*your code here*/){ 142 | /*your code here*/ 143 | } 144 | 145 | 146 | 147 | /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 148 | July 7th is "World Chocolate Day" and Baskin Robins wants to create promotional materials highlighting all of their chocolate flavors. 149 | Your task is to write a function that checks every item in the array for a string and returns a new array called filteredArray with only the values that contain the received string. This would allow you to be able to filter for "Vanilla", "Sherbet", "Lemon" etc. when different holidays roll around by passing in those specific strings. 150 | 151 | Use the filterByWord function below to do the following: 152 | 1. Receive an array in the first parameter that will take the flavors array as an argument 153 | 2. Receive a string in the second parameter that will take the filter value as as an argument (example: "chocolate") 154 | 3. Check to see if any of the flavors in the array contain that string 155 | 4. If they do, add them to a new array 156 | 5. Return the new array that contains the filtered flavors 157 | 158 | For example: filterByWord(originalFlavors, "Chocolate") should return ["Chocolate", "Chocolate Almond", "Chocolate Chip", "Chocolate Fudge", "Chocolate Mint", "Chocolate Ribbon"] 159 | 160 | HINT - you can use the .includes method to help you solve this 161 | 162 | DO NOT USE ADVANCED ARRAY METHODS (i.e. .filter) to solve this problem. 163 | */ 164 | 165 | 166 | function filterByWord(/*your code here*/){ 167 | /*your code here*/ 168 | } 169 | 170 | 171 | 172 | /* 💪💪💪💪💪🧁🍦🍨 STRETCH 🍨🍦🍫💪💪💪💪💪*/ 173 | 174 | /* STRETCH 1: Write a function that returns the average number of words in an array. You should be able to use this function for any array, but can test with originalFlavors. 175 | 176 | Use the getAverageWordLength function below to do the following: 177 | 1. Receive the originalFlavors array 178 | 2. Count how many words per item in the array 179 | 3. Return the average number of words per item in the array 180 | 181 | For example: getAverageWordLength(originalFlavors) should return a number between 0 and 3. 182 | */ 183 | 184 | function getAverageWordLength(/*code here*/){ 185 | /*code here*/ 186 | } 187 | 188 | 189 | /* 💪💪💪💪💪💪💪💪💪💪 STRETCH 2: 💪💪💪💪💪💪💪💪💪 190 | Baskin Robins now offers new flavors, seasonal flavors, and even regional flavors. Write a function that will randomly select a total of 31 flavors 191 | from originalFlavors, currentFlavors, seasonalFlavors, and regionalFlavors and store it in an array called randomFlavors. 192 | 193 | Use the getRandomFlavors function and new arrays below to do the following: 194 | 1. Receive the four arrays with all the differnet flavors (originalFlavors is above, the others are below) 195 | 2. Randomly pick flavors from all four arrays 196 | 3. Return a new array called randomFlavors that has a lenght of 31 197 | 198 | For example: getRandomFlavors(originalFlavors, newFlavors, seasonalFlavors, regionalFlavors) might return ["Strawberry Cheesecake", "Eggnog,"..."Chocolate"]. 199 | */ 200 | 201 | 202 | function getRandomFlavors(/*code here*/){ 203 | /*code here*/ 204 | } 205 | 206 | // NEW DATA ARRAYS FOR STRETCH 2 ⬇️ 207 | // const newFlavors = [ 208 | // "Date night", 209 | // "U.S.S Butterscotch (Stranger Things special)", 210 | // "Honey Almond", 211 | // "Mint Chocolate Chip", 212 | // "Chocolate", 213 | // "Oreo® Cookies'n Cream", 214 | // "Chocolate Chip", 215 | // "Pralines 'n Cream", 216 | // "Very Berry Strawberry", 217 | // "Chocolate Chip Cookie Dough", 218 | // "Old Fashioned Butter Pecan", 219 | // "Jamoca®", 220 | // "Jamoca® Almond Fudge", 221 | // "Reese's® Peanut Butter Cup", 222 | // "Rocky Road", 223 | // "Peanut Butter ’n Chocolate", 224 | // "Gold Medal Ribbon®", 225 | // "World Class® Chocolate", 226 | // "Cherries Jubilee", 227 | // "Chocolate Fudge", 228 | // "Daiquiri Ice", 229 | // "Rainbow Sherbet", 230 | // "Rainbow Swirl" 231 | // ] 232 | 233 | // const seasonalFlavors = [ 234 | // "America's Birthday Cake", 235 | // "Baseball Nut®", 236 | // "Blueberry Cheesecake", 237 | // "Bourbon Street Pecan Pie", 238 | // "Brownie Bar Mashup", 239 | // "Cherry Cordial with Kisses", 240 | // "Chocolate Mousse Royale", 241 | // "French Vanilla", 242 | // "Eggnog", 243 | // "German Chocolate Cake", 244 | // "Icing on the Cake", 245 | // "Love Potion #31", 246 | // "New York Cheesecake", 247 | // "Nutty Coconut", 248 | // "Peppermint", 249 | // "Strawberry Cheesecake", 250 | // "Rock ’n Pop Swirl", 251 | // "Reese’s Peanut Butter Cup", 252 | // "Trick Oreo Treat", 253 | // "Winter White Chocolate", 254 | // "made with Snickers®", 255 | // "made with M&M's®", 256 | // "Heath®", 257 | // "Mango Tango" 258 | // ] 259 | 260 | // const regionalFlavors = [ 261 | // "Pink Bubblegum", 262 | // "Caramel Macchiato", 263 | // "York Peppermint Pattie", 264 | // "Cotton Candy", 265 | // "Orange Sherbet", 266 | // "Grape Ice", 267 | // "Watermelon Ice", 268 | // "Miami Vice Sorbet", 269 | // "Splish Splash®", 270 | // "Wild 'n Reckless Sherbet", 271 | // "Lemon Custard", 272 | // "Oregon Blackberry", 273 | // "Bananas ‘n Strawberries", 274 | // "Mississippi Mud", 275 | // "Rum Raisin", 276 | // "Creole Cream Cheese", 277 | // "Chocolate Almond", 278 | // "Fudge Brownie", 279 | // "Banana Nut", 280 | // "Black Walnut", 281 | // "Cotton Candy Crackle", 282 | // "Quarterback Crunch", 283 | // "Chocolate Chocolate Chip Cheesecake", 284 | // "Caramel 'n' Cookies" 285 | // ] 286 | 287 | 288 | 289 | /* 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 */ 290 | function foo(){ 291 | console.log('its working'); 292 | return 'bar'; 293 | } 294 | foo(); 295 | module.exports = { 296 | foo, 297 | is31Flavors, 298 | addFlavor, 299 | removeLastFlavor, 300 | getFlavorByIndex, 301 | removeFlavorByName, 302 | copy, 303 | filterByWord, 304 | getAverageWordLength, 305 | getRandomFlavors 306 | } 307 | 308 | --------------------------------------------------------------------------------