GithubHelp home page GithubHelp logo

phase-0-intro-to-js-2-array-lab's Introduction

Arrays Lab

Learning Goals

  • Practice writing arrays
  • Practice using destructive methods to manipulate arrays
  • Practice using nondestructive methods to manipulate arrays

Introduction

We've learned about how arrays work and about the array methods built in to JavaScript that we can use to manipulate them. Now it's time to practice what we've learned.

If you haven't already, fork and clone this lab into your local environment. Navigate into its directory in the terminal, then run code . to open the files in Visual Studio Code.

Instructions

Open up the test folder and take a look at indexTest.js. Note that some of the names of the functions you will be writing begin with destructively and some don't. This is a clue as to which Array method you will need to use for each function.

Note also that the first test asks for an array called cats, set to an initial value of ["Milo", "Otis", "Garfield"]. In your functions, you will be accessing and manipulating this array.

Near the top of indexTest.js you will see the following:

beforeEach(function () {
  cats.length = 0;

  cats.push("Milo", "Otis", "Garfield");
});

What this code does is reset the array to its original contents before each test is run. The reason we need to do this is because some of your functions will be destructive โ€” they will change the original cats array. This is a problem because it means the input to the remaining functions will be dependent on the outcome of other functions. It also means that the expected return value of a function might change if the tests are run in a different order. This makes it more difficult both to write tests in the first place and to figure out how to get the tests to pass. Resetting the array returns us to a blank slate between tests.

This is also a good illustration of why it's generally good practice to avoid mutating a program's state whenever possible. If we use only nondestructive methods, we have complete control over what's going into and coming out of the function. This makes our programs more robust, easier to maintain, and less prone to bugs.

Remember the workflow:

  1. Install the dependencies using npm install.
  2. Run the tests using npm test.
  3. Read the errors; vocalize what they're asking you to do.
  4. Write code; repeat steps 2 and 3 often until a test passes.
  5. Repeat as needed for the remaining tests.

After you have all the tests passing, remember to commit and push your changes up to GitHub, then submit your work to Canvas using CodeGrade.

phase-0-intro-to-js-2-array-lab's People

Contributors

bal360 avatar drakeltheryuujin avatar gj avatar ihollander avatar jeffkatzy avatar jlboba avatar jmburges avatar lizbur10 avatar maxwellbenton avatar sgharms avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phase-0-intro-to-js-2-array-lab's Issues

gives wrong command to run test

In the bottom of the canvas instructions it says

Remember the workflow:
Run the tests using learn test.

learn test does not work. npm test should be the command given. the github readme has the right command but doesnt match what is on canvas

npm test results are broken

Thanks for raising this issue! Future learners thank you for your diligence. In
order to help the curriculum team address the problem, please use this template
to submit your feedback. We'll work on addressing the issue as soon as we can.

Please fill out as much of the information below as you can (it's ok if you
don't fill out every section). The more context we have, the easier it will be
to fix your issue!

Note: you should only raise issues related to the contents of this lesson.
If you have questions about your code or need help troubleshooting, reach out to
an instructor/your peers.


Link to Canvas

Add a link to the assignment in Canvas here.

Describe the bug

Write a clear and concise description of what the bug is. Include the file and
line number(s) if possible.
When running npm test initially, returns this
$ npm test

[email protected] test
mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json

  1. "before all" hook

0 passing (8s)
1 failing

  1. "before all" hook:
    Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
    at Object.done (node_modules/mocha-jsdom/index.js:70:7)
    at /mnt/d/Programming/FlatironSchool/code/phase0/phase-0-intro-to-js-2-array-lab/node_modules/jsdom/lib/jsdom.js:312:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

What is the expected behavior?

Write a clear and concise description of what you expected to happen.

Screenshots

If applicable, attach screenshots to help explain your problem.

What OS are you using?

  • OS X
  • WSL
  • Linux

Any additional context?

Add any other context about the problem here.

Directs to Phase-0 Assignment

This lab leads to phase-0-intro-to-js-2-array-lab. If this is the lab for this sections and it is a repeat of a previous lab, it would be good to know before beginning the assignment to avoid confusion! Thank you <3

Fork Already Exists

Canvas Link

https://learning.flatironschool.com/courses/6557/assignments/242757?module_item_id=571160

Concern

Create a new fork
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.

No more forks can be created. These forks already exist:

(https://github.com/ckelly38/phase-0-intro-to-js-2-array-lab?organization=ckelly38&organization=ckelly38)

Additional Context

Is the Arrays Lab for Phase 1 the same as the Arrays Lab for Phase 0? If so, that should be NOTED. If not, then wrong github link is posted.

Suggested Changes

No response

Re submit

I accidentally pushed before my last edit was done. Can I resubmit or have I failed the lab?

npm test not working?

Canvas Link

https://learning.flatironschool.com/courses/7618/assignments/267835?module_item_id=643839

Concern

Hello, need some help troubleshooting after forking and cloning a lab. I forked and cloned to my local environment (Mac) and then ran npm install as usual, but when I run npm test, I don't get any tests, instead I get this. Any advice? If this is something I should take to the general Discord just let me know.
Screenshot 2024-02-01 at 10 29 28

Additional Context

No response

Suggested Changes

No response

Same as pre work

This lab seems to be the same as prework and is listed as phase 0. It wont mark as complete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.