how the below function is pure → in my opinion , every time we pass in the car object as an argument in accelerate(), it returns us an new object and an object is a non-primitive datatype and it makes comparison based on references. so, every time accelerate() is returning us a new object (references different for everyone) , That’s ,makes it a impure function ( on same input , we got different output) .
so how that function is pure(told in the course)? plz explain…
var car = { speed: 0, seats: 5 };
function accelerate(car) {
car.speed += 1;
return car;
}
console.log(accelerate(car));
console.log(accelerate(car));
console.log(accelerate(car) === accelerate(car)) //false
Course: https://www.educative.io/courses/react-beginner-to-advanced
Lesson: Pure Functions in Detail - React Deep Dive: From Beginner to Advanced