Giter Club home page Giter Club logo

Comments (2)

mduleone avatar mduleone commented on June 28, 2024

The solutions branch solves this by using a for loop and mutating the cart array. However, it can be much cleaner if it doesn't require mutation:

function removeFromCart(item) {
  const newCart = cart.filter(el => !el.hasOwnProperty(item));

  if (newCart.length === cart.length) {
    console.log('That item is not in your cart.');
  }

  return newCart;
}

Making this sample code mutate is as simple as adding cart = newCart; immediately before the return, and I understand that Array.prototype functions may be outside the scope of this course, but they are still a valid way to solve the problem.

For clarity, I'm a Senior Frontend Engineer looking at these problems because my roommate is looking to apply to FlatIron School. I wanted to understand what he's working through so I could offer help if he needed it. I enjoy solving toy problems, so I decided to solve these. I was surprised when removeFromCart required mutation.

from js-basics-online-shopping-lab-bootcamp-prep-000.

mduleone avatar mduleone commented on June 28, 2024

I opened #1055 to update the test to pass if the element is removed from the returned array (and therefore is true to the instructions), whether the global cart variable is mutated or not.

from js-basics-online-shopping-lab-bootcamp-prep-000.

Related Issues (2)

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.