Comments (2)
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-basics-online-shopping-lab-bootcamp-prep-000.