├── .canvas ├── .editorconfig ├── .github └── workflows │ └── canvas-sync-ruby-update.yml ├── .gitignore ├── .learn ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── index.html ├── index.js ├── package.json └── test ├── helpers.js └── indexTest.js /.canvas: -------------------------------------------------------------------------------- 1 | --- 2 | :lessons: 3 | - :id: 218941 4 | :course_id: 6602 5 | :canvas_url: https://learning.flatironschool.com/courses/6602/assignments/218941 6 | :type: assignment 7 | - :id: 223910 8 | :course_id: 6638 9 | :canvas_url: https://learning.flatironschool.com/courses/6638/assignments/223910 10 | :type: assignment 11 | - :id: 263262 12 | :course_id: 7550 13 | :canvas_url: https://learning.flatironschool.com/courses/7550/assignments/263262 14 | :type: assignment 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | insert_final_newline = true 7 | 8 | [*{.java,.py}] 9 | indent_size = 4 10 | 11 | [*.{js,json,rb}] 12 | charset = utf-8 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /.github/workflows/canvas-sync-ruby-update.yml: -------------------------------------------------------------------------------- 1 | name: Sync with Canvas Ruby v2.7 2 | 3 | on: 4 | push: 5 | branches: [master, main] 6 | paths: 7 | - 'README.md' 8 | 9 | jobs: 10 | sync: 11 | name: Sync with Canvas 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | 18 | - name: Set up Ruby 19 | uses: ruby/setup-ruby@v1 20 | with: 21 | ruby-version: 2.7 22 | 23 | - name: Install github-to-canvas 24 | run: gem install github-to-canvas 25 | 26 | # Secret stored in learn-co-curriculum Settings/Secrets 27 | - name: Sync from .canvas file 28 | run: github-to-canvas -a -lr 29 | env: 30 | CANVAS_API_KEY: ${{ secrets.CANVAS_API_KEY }} 31 | CANVAS_API_PATH: ${{ secrets.CANVAS_API_PATH }} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/node 2 | 3 | .DS_Store 4 | 5 | ### Node ### 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directories 23 | node_modules 24 | jspm_packages 25 | 26 | # Optional npm cache directory 27 | .npm 28 | 29 | # Optional REPL history 30 | .node_repl_history 31 | 32 | # Learn-specific .results.json 33 | .results.json 34 | 35 | # Ignore bundler config. 36 | /.bundle 37 | 38 | # Ignore the default SQLite database. 39 | /db/*.sqlite3 40 | /db/*.sqlite3-journal 41 | 42 | # Ignore all logfiles and tempfiles. 43 | /log/* 44 | !/log/.keep 45 | /tmp 46 | 47 | 48 | -------------------------------------------------------------------------------- /.learn: -------------------------------------------------------------------------------- 1 | tags: 2 | - lab 3 | - data structures 4 | - objects 5 | languages: 6 | - javascript 7 | resources: 8 | - 1 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Learn.co Curriculum 2 | 3 | We're really excited that you're about to contribute to the [open 4 | curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). 5 | If this is your first time contributing, please continue reading to learn how 6 | to make the most meaningful and useful impact possible. 7 | 8 | ## Raising an Issue to Encourage a Contribution 9 | 10 | If you notice a problem with the curriculum that you believe needs improvement 11 | but you're unable to make the change yourself, you should raise a Github issue 12 | containing a clear description of the problem. Include relevant snippets of 13 | the content and/or screenshots if applicable. Curriculum owners regularly review 14 | issue lists and your issue will be prioritized and addressed as appropriate. 15 | 16 | ## Submitting a Pull Request to Suggest an Improvement 17 | 18 | If you see an opportunity for improvement and can make the change yourself go 19 | ahead and use a typical git workflow to make it happen: 20 | 21 | * Fork this curriculum repository 22 | * Make the change on your fork, with descriptive commits in the standard format 23 | * Open a Pull Request against this repo 24 | 25 | A curriculum owner will review your change and approve or comment on it in due 26 | course. 27 | 28 | # Why Contribute? 29 | 30 | Curriculum on Learn is publicly and freely available under Learn's 31 | [Educational Content License](https://learn.co/content-license). By 32 | embracing an open-source contribution model, our goal is for the curriculum 33 | on Learn to become, in time, the best educational content the world has 34 | ever seen. 35 | 36 | We need help from the community of Learners to maintain and improve the 37 | educational content. Everything from fixing typos, to correcting 38 | out-dated information, to improving exposition, to adding better examples, 39 | to fixing tests—all contributions to making the curriculum more effective are 40 | welcome. 41 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Learn.co Educational Content License 2 | 3 | Copyright (c) 2018 Flatiron School, Inc 4 | 5 | The Flatiron School, Inc. owns this Educational Content. However, the Flatiron 6 | School supports the development and availability of educational materials in 7 | the public domain. Therefore, the Flatiron School grants Users of the Flatiron 8 | Educational Content set forth in this repository certain rights to reuse, build 9 | upon and share such Educational Content subject to the terms of the Educational 10 | Content License set forth [here](http://learn.co/content-license) 11 | (http://learn.co/content-license). You must read carefully the terms and 12 | conditions contained in the Educational Content License as such terms govern 13 | access to and use of the Educational Content. 14 | 15 | Flatiron School is willing to allow you access to and use of the Educational 16 | Content only on the condition that you accept all of the terms and conditions 17 | contained in the Educational Content License set forth 18 | [here](http://learn.co/content-license) (http://learn.co/content-license). By 19 | accessing and/or using the Educational Content, you are agreeing to all of the 20 | terms and conditions contained in the Educational Content License. If you do 21 | not agree to any or all of the terms of the Educational Content License, you 22 | are prohibited from accessing, reviewing or using in any way the Educational 23 | Content. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Objects Lab 2 | 3 | ## Learning Goals 4 | 5 | - Create an `Object` 6 | - Perform operations on an `Object` 7 | 8 | ## Introduction 9 | 10 | We covered the concepts of `Object`s in JavaScript. Now it's time to put the 11 | concepts into practice. 12 | 13 | If you haven't already, **fork and clone** this lab into your local environment. 14 | Navigate into its directory in the terminal, then run `code .` to open the files 15 | in Visual Studio Code. 16 | 17 | ## Instructions 18 | 19 | Follow the steps below, running `npm test` as you go to get additional 20 | information from the tests. Don't forget to run `npm install` first! 21 | 22 | Let's say we are working on a program that will keep track of a company's 23 | employees. We want to store each `employee` as an `Object`. We're starting 24 | small, so to begin with we'll only keep track of the employee's name and street 25 | address. 26 | 27 | To start, assign an `employee` variable to an `Object` containing 28 | `name` and `streetAddress` keys; you can use whatever values you like. Use 29 | literal syntax to create your `Object`. Various updates will be applied to this 30 | variable (destructively and non-destructively) in this lab. 31 | 32 | Once you've initialized the `employee` Object, you'll need to create the 33 | following four functions: 34 | 35 | - `updateEmployeeWithKeyAndValue()`: this function should take in three 36 | arguments: an `employee` `Object`, a `key` and a `value`. This function should 37 | not mutate the `employee`; it should return a _new_ `Object` that has an 38 | updated `value` for the `key` passed in. **Hint**: use the spread operator! 39 | - `destructivelyUpdateEmployeeWithKeyAndValue()`: this function should work the 40 | same as `updateEmployeeWithKeyAndValue()` but it _should_ mutate the 41 | `employee` `Object` passed in. 42 | - `deleteFromEmployeeByKey()`: this function should take in a `employee` 43 | `Object` and a `key`. It should delete the property with that `key` from the 44 | `employee` `Object`. This should not mutate the original `employee` `Object`; 45 | it should return a _new_ `Object` that doesn't include the identified 46 | key-value pair. **Hint**: use the spread operator! 47 | - `destructivelyDeleteFromEmployeeByKey()`: this function should work the same 48 | as `deleteFromEmployeeByKey()` but it _should_ mutate the `employee` `Object`. 49 | 50 | As you work on your functions, be sure to think about when to use dot notation 51 | vs. bracket notation. 52 | 53 | After you have all the tests passing, remember to commit and push your changes 54 | up to GitHub, then submit your work to Canvas using CodeGrade. 55 | 56 | ## Conclusion 57 | 58 | In this lab, we practiced creating an `Object` and performing operations on it. 59 | 60 | ## Resources 61 | 62 | - [MDN: Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) 63 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | JavaScript Objects Lab 8 | 9 | 10 | 11 | 12 | hello 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Write your solution in this file! 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js-data-structures-objects-lab", 3 | "version": "0.1.0", 4 | "description": "Learn.co's practice with manipulating JavaScript objects.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json --timeout 10000" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/learn-co-curriculum/js-data-structures-objects-lab.git" 12 | }, 13 | "keywords": [ 14 | "javascript", 15 | "for", 16 | "while", 17 | "loops", 18 | "looping", 19 | "learn.co", 20 | "flatiron school", 21 | "code-along" 22 | ], 23 | "author": "Flatiron School", 24 | "license": "SEE LICENSE IN LICENSE.md", 25 | "bugs": { 26 | "url": "https://github.com/learn-co-curriculum/js-data-structures-objects-lab/issues" 27 | }, 28 | "homepage": "https://github.com/learn-co-curriculum/js-data-structures-objects-lab#readme", 29 | "dependencies": { 30 | "@babel/core": "^7.4.5", 31 | "@babel/preset-env": "^7.4.5", 32 | "chai": "^4.2.0", 33 | "jsdom": "^9.0", 34 | "mocha": "5.2.0", 35 | "mocha-jsdom": "~1.1.0", 36 | "mocha-multi": "^1.0.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/helpers.js: -------------------------------------------------------------------------------- 1 | const chai = require('chai') 2 | global.expect = chai.expect 3 | const fs = require('fs') 4 | const jsdom = require('mocha-jsdom') 5 | const path = require('path') 6 | const babel = require("@babel/core"); 7 | const url = "http://localhost" 8 | 9 | const html = fs.readFileSync(path.resolve(__dirname, '..', 'index.html'), 'utf-8') 10 | 11 | const babelResult = babel.transformFileSync( 12 | path.resolve(__dirname, '..', 'index.js'), { 13 | presets: ['@babel/env'] 14 | } 15 | ); 16 | 17 | const src = babelResult.code 18 | 19 | jsdom({ 20 | html, src, url 21 | }); 22 | -------------------------------------------------------------------------------- /test/indexTest.js: -------------------------------------------------------------------------------- 1 | require ( './helpers.js' ); 2 | 3 | describe('employees', function() { 4 | describe('updateEmployeeWithKeyAndValue(employee, key, value)', function () { 5 | beforeEach(function () { 6 | for (const key in employee) { 7 | delete employee[key]; 8 | } 9 | 10 | employee.name = 'Sam'; 11 | }); 12 | 13 | it('returns an employee with the original key value pairs and the new key value pair', function () { 14 | expect(updateEmployeeWithKeyAndValue(employee, 'streetAddress', '11 Broadway')).to.eql({ 15 | name: 'Sam', 16 | streetAddress: '11 Broadway' 17 | }); 18 | }); 19 | 20 | it('it does not modify the original employee, but rather returns a clone with the new data', function () { 21 | updateEmployeeWithKeyAndValue(employee, 'streetAddress', '11 Broadway'); 22 | 23 | expect(employee['streetAddress']).to.equal(undefined); 24 | }); 25 | }); 26 | 27 | describe('destructivelyUpdateEmployeeWithKeyAndValue(employee, key, value)', function () { 28 | it('updates `employee` with the given `key` and `value` (it is destructive) and returns the entire updated employee', function () { 29 | expect(destructivelyUpdateEmployeeWithKeyAndValue(employee, 'streetAddress', '12 Broadway')).to.eql({ 30 | name: 'Sam', 31 | streetAddress: '12 Broadway' 32 | }); 33 | 34 | expect(employee).to.eql({ 35 | name: 'Sam', 36 | streetAddress: '12 Broadway' 37 | }); 38 | }); 39 | }); 40 | 41 | describe('deleteFromEmployeeByKey(employee, key)', function () { 42 | it('deletes `key` from a clone of employee and returns the new employee (it is non-destructive)', function () { 43 | let newEmployee = deleteFromEmployeeByKey(employee, 'name'); 44 | 45 | expect(newEmployee['name']).to.equal(undefined); 46 | expect(typeof newEmployee).to.equal('object'); 47 | }); 48 | 49 | it('does not modify the original employee (it is non-destructive)', function () { 50 | deleteFromEmployeeByKey(employee, 'name'); 51 | 52 | expect(employee['name']).to.equal('Sam'); 53 | }); 54 | }); 55 | 56 | describe('destructivelyDeleteFromEmployeeByKey(employee, key)', function () { 57 | it('returns employee without the deleted key/value pair', function () { 58 | let newEmployee = destructivelyDeleteFromEmployeeByKey(employee, 'name'); 59 | 60 | expect(newEmployee['name']).to.equal(undefined); 61 | }); 62 | 63 | it('modifies the original employee', function () { 64 | let newEmployee = destructivelyDeleteFromEmployeeByKey(employee, 'name'); 65 | 66 | expect(employee['name']).to.equal(undefined); 67 | expect(employee).to.equal(newEmployee); 68 | }); 69 | }); 70 | }); 71 | --------------------------------------------------------------------------------